$(".p").each(function(i){
len=$(this).text().length;
if(len>80)
{
$(this).text($(this).text().substr(0,80)+'...');
}
});
我的一些输出很好,比如
abc def...
但其中一些会像
1234 45 ...
如何 trim 空间?我尝试了 $.trim 但不起作用。
最佳答案
这应该有效:
$(".p").text(function() {
var text = $(this).text();
if (text.length > 80) {
return $.trim(text.substr(0, 80)) + '...';
} else {
return text;
}
});
关于javascript - 使用 $.trim 的 $.trim 空间在 Jquery 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27727620/