我正在尝试 trim 和缩短一些 HTML。我使用这段代码:
$(window).bind("load", function() {
$.trim('a').substring(0, 10).split(" ").slice(0, - 1).join(" ") + "...";
});
这不起作用。我尝试了很多方法,但似乎无法使其工作......看一下示例:JsFiddle
最佳答案
我想你的意思是something like :
$('a').each(function(i,el) {
el = $(el);
old = $.trim(el.html());
el.html( old.substring(0, 10).split(" ").slice(0, -1).join(" ") + "..." );
});
或者:
$('a').html(
function(){
return $.trim($(this).html())
.substring(0, 10)
.split(" ").slice(0, -1)
.join(" ") + "...";}
);
关于javascript - jQuery 事件 trim 对我不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11807487/