问题标题总结了,我不知道还有什么要详细说明。
在任何人提到CSS3属性text-overflow:ellipsis
之前我不能使用它,因为当包含的div中有几个<p>
时它将不起作用。谢谢!
答案 0 :(得分:2)
$('p').each(function() {
var txt = $(this).text();
if (txt.length>100) {
$(this).text(txt.substring(0,100)+'...');
}
});
或者也许:
$('p').each(function() {
var txt = $(this).text();
if (txt.length>100) {
$(this).html('<span>'+txt.substring(0,100)+' </span><a href="somemore">Read More</a>');
}
});
答案 1 :(得分:1)
我为这一段时间写了一个插件。我不再维护它,但它应该仍然有效:http://www.jeremymartin.name/projects.php?project=jTruncate