我有500多个字符的段落。我只想得到最初的100个字符并隐藏其余部分。另外我想在100个字符旁边插入“更多”链接。点击更多链接整个段落应显示和编辑文本“更多”到“更少”,并点击“更少”它应该切换行为。段落是动态生成的,我无法用.wrap()包装它的内容。这里是我拥有的和我想要的例子。截取段落前100个字符并隐藏段落的其余内容显示/隐藏其他链接的链接
这是我有:
<p>It is a long established fact that a reader will be distracted by the readable
content of a page when looking at its layout. The point of using Lorem Ipsum is that
it has a more-or-less normal distribution of letters, as opposed to using 'Content
content here', making it look like readable English. Many desktop publishing packages
and web page editors now use Lorem Ipsum as their default model text.</p>
这就是我想要什么,当DOM加载
<p>It is a long established fact that a reader will be distracted by ..More</p>
这就是我想要的东西,当用户点击 “更多”
<p>It is a long established fact that a reader will be distracted by the readable
content of a page when looking at its layout. The point of using Lorem Ipsum is that
it has a more-or-less normal distribution of letters, as opposed to using 'Content
content here', making it look like readable English. Many desktop publishing packages
and web page editors now use Lorem Ipsum as their default model text. ..Less</p>
当我们点击“较少”时,它应该恢复点击“更多”所做的事情。
我正在使用jQuery来分割,切片并将子字符串换成跨度,我想要隐藏但是不起作用。
var title = $("p").text();
var shortText = jQuery.trim(title).substring(100, 1000).split(" ")
.slice(0, -1).join(" ") + "...More >>";
shortText.wrap('</span>');
你试过了什么?也许你可以发布一些代码来显示你的尝试 – 2012-07-10 16:18:13
我已经添加了代码示例。 var shortText我想把它包装成span标签。但.wrap()不起作用。 – 2012-07-10 16:27:26