Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我们如何在第 10 个字符之后在句子中添加 html 元素
var $element = $(someselector); var text = $element.text(); $element.html(text.slice(0, 10) + '<span>new thing</span>' + text.slice(10));
示范
请注意,这仅在 $element 仅包含一个对象时才有效。对于集合,您将使用每个(如果需要,我将详细说明此代码)。