是否有可能用字符串标记排除第一个字的字符串中的最后一个字?所以这将会是例如:如何在span标签中包装除jQuery之外的第一个单词?
var string = 'My super text';
变为
My <span>super text</span>
我有这样的:
var text= string.split(" ");
// drop the last word and store it in a variable
var last = text.pop();
// join the text back and if it has more than 1 word add the span tag
// to the last word
if (text.length > 0) {
return text.join(" ") + " <span>" + last + "</span>";
} else {
return "<span>" + text.join(" ") + last + "</span>";
}
与span标签包装的最后一个字,如果它有至少两个但不确定如何修改它。
在此先感谢!
真棒的感谢! – javiervd