我正在尝试按字符数裁剪文本:
$(".text-article").text(function(i, text) {
if (text.lenght >= 10) {
text = text.substr(0, 10);
let lastIndex = text.lastIndexOf(" ");
text = text.substr(0, lastIndex) + '...';
}
$(this).text(text);
});
什么也没有发生,但是如果您在控制台中直接剪切文本,那么一切都很好。我无法弄清楚问题是什么。html 代码创建一个 php 脚本,也许这是问题所在?
1 个回答