//
ドキュメント内で (スラッシュ)を見つけて . で囲もうとしていspan
ます。
私はもう試した
var slashes = "//";
/slashes+/
したがって、出力は次のようになります。
Hello There! I Am <span class="slashes">//</span> An Alien
jQuery .replace()
and :contains
but では何も起こりません。これを正しく行うための正規表現は初めてです。どうすればいいですか?
編集:私が試したこと: この質問の解決策はうまくいきませんでした:
function slashes($el) {
$el.contents().each(function () {
dlbSlash = "//";
if (this.nodeType == 3) { // Text only
$(this).replaceWith($(this).text()
.replace(/(dlbSlash)/gi, '<span class="slashes">$1</span>'));
} else { // Child element
slashes($(this));
}
});
}
slashes($("body"));