Javascript 如何将第十一个字符替换为“&引用;

Javascript 如何将第十一个字符替换为“&引用;,javascript,jquery,Javascript,Jquery,我的div中有一个很长的文本。我希望它只显示10个字符,然后剩下的内容被…替换 <div id="name">wahahahahahahahahahahaha</div> 这个jQuery起作用了,长文本一直停到第十个 添加条件以检查文本是否超过10个字符 $("div#name").text(function(index, currentText) { var newText = currentText.substr(0, 10); if(cur

我的div中有一个很长的文本。我希望它只显示10个字符,然后剩下的内容被
替换

<div id="name">wahahahahahahahahahahaha</div>

这个jQuery起作用了,长文本一直停到第十个

添加条件以检查文本是否超过10个字符

$("div#name").text(function(index, currentText) {   
    var newText = currentText.substr(0, 10);
    if(currentText.length > 10)
       newText += "...";

    return newText ;
});

添加条件以检查文本是否超过10个字符

$("div#name").text(function(index, currentText) {   
    var newText = currentText.substr(0, 10);
    if(currentText.length > 10)
       newText += "...";

    return newText ;
});

添加条件以检查文本是否超过10个字符

$("div#name").text(function(index, currentText) {   
    var newText = currentText.substr(0, 10);
    if(currentText.length > 10)
       newText += "...";

    return newText ;
});

添加条件以检查文本是否超过10个字符

$("div#name").text(function(index, currentText) {   
    var newText = currentText.substr(0, 10);
    if(currentText.length > 10)
       newText += "...";

    return newText ;
});

为什么不直接使用纯css和文本溢出:省略号。使用jquery来实现这一点简直是过火了@unikorn我试过了在我的电脑里不起作用code@TheSmile溢出必须与可见溢出不同。为什么不使用纯css和文本溢出:省略号。使用jquery来实现这一点简直是过火了@unikorn我试过了在我的电脑里不起作用code@TheSmile溢出必须与可见溢出不同。为什么不使用纯css和文本溢出:省略号。使用jquery来实现这一点简直是过火了@unikorn我试过了在我的电脑里不起作用code@TheSmile溢出必须与可见溢出不同。为什么不使用纯css和文本溢出:省略号。使用jquery来实现这一点简直是过火了@unikorn我试过了在我的电脑里不起作用code@TheSmile溢出必须与可见溢出不同。该工作了,非常感谢你!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!我稍后会勾选这个答案。。。再次感谢!非常感谢你!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!我稍后会勾选这个答案。。。再次感谢!非常感谢你!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!我稍后会勾选这个答案。。。再次感谢!非常感谢你!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!我稍后会勾选这个答案。。。再次感谢!