我在这里写了这段代码:
var title = "This is my comment for my title";
title.replace(/['"`!#()_:\/\.\?]|&[^;]+;/g, '').substring(0, 20);
这让我得到了前 20 个字符,但是我想找到最近的空格并替换为...
我该怎么做?
JQuery 的新手
现在它返回这个... This is my comment f
,我想返回This is my comment...
我尝试添加此代码:
title = title.substr(title.indexOf(" ")) + "...";
但它This
从我的变量中删除。