Мой вопрос очень похож на "Обрезать текст до 340 символов, но в jQuery. Это звучало очень прямо, но когда я искал вокруг, я не мог найти никаких ссылок на него.
Хорошо, у меня есть div $('#content')
Я хочу обрезать текст до "х", количество символов позволяет сказать "600" НО. Я не хочу, чтобы он сломал слово сам! Как НЕ ' Ques...' НО ' Вопросы...'.
Что происходит с остальной частью текста? Хорошо, я спрячу его и покажу его по запросу! Но подождите, сначала нужно удалить "..." и показать текст сразу после того, как он скроется.
Вот структура образца для $('# content'):
<div id="content">
<p>Once upon a midnight dreary, while I pondered weak and weary,Over many a quaint and curious volume of forgotten lore.</p>
<p>Writing example text is very boring.</p>
<p>Specially when you are dumb enough not to copy and paste. Oh!</p>
<p>Once it sheltered the rogues and rapscallions of the British Empire; now Kangaroo Island is ready and waiting for some derring-do of your own. Venture into the rugged wilds of the island, traversing untamed bushland and pristine beaches seeking out seal, penguin and sea lion colonies. Meet the land loving locals - koalas, goannas, echidnas and the island own species of kangaroo. </p>
</div>
Как он должен загружаться:
Однажды в полночь тоскливо, пока я размышлял о слабых и усталых, странный и любопытный объем забытых уздечка.
Написание текста примера... [Читать Подробнее]
После нажатия кнопки "Подробнее":
Однажды в полночь тоскливо, пока я размышлял о слабых и усталых, странный и любопытный объем забытых уздечка.
Написание текста примера очень скучно.
Специально, когда вы достаточно глупы, для копирования и вставки. О!
Как только он укрыл мошенников и осколки Британской империи; теперь остров Кенгуру готов и ожидая некоторого дергания вашего своя. Участвуйте в суровых остров, пересекающий неприрученный бушленд и нетронутые пляжи тюлень, пингвин и морской лев колонии. Познакомьтесь с земляками, любящими локальных жителей - коалы, конаны, эхидны и островные виды кенгуру.
UPDATE: Я нашел эти два плагина, которые выполняют ту же работу, что и этот лучший ответ. Однако лучший ответ имеет некоторые функции, которые эти плагины не имеют и наоборот!