最後の単語を、最初の単語を除くスパンタグを含む文字列にラップすることはできますか?だから、たとえばだろう:jQueryで最初の単語を除くスパンタグにテキストをラップする方法は?
var string = 'My super text';
は
My <span>super text</span>
になり、私はこれを持っている:
それは少なくとも二つのではなく、を持っている場合は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>";
}
それを変更する方法を確認してください。
ありがとうございます!
素晴らしい感謝! – javiervd