我有一个div,其中包含可变数量的文本。 div的高度已设置,如果文本超出该高度,我想创建一个“阅读更多”链接。
我能够算出div的长度,例如:
$(".longdesc").each(function() {
var count = $(this).text().length
console.log(count);
if(count > 100){
//Replace additional characters with " ...Read More"
};
});
但是我不确定如何将第100个字符后的所有字符替换为“ ...阅读更多”。
有人知道该怎么做吗?
最佳答案
if(count > 100){
$(this).text($(this).text().substring(0, 100) + " ...Read More");
};
关于javascript - 使用jQuery替换第n个字符后的所有字符,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18370872/