是否有可能用字符串標記排除第一個字的字符串中的最後一個字?所以這將會是例如:如何在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