Jquery替换字符串中的标签

时间:2017-09-13 14:57:42

标签: jquery

我有这样的字符串:

"<p>Some text <em>Italic string</em> ... </p><em>Second str</em>"

如何将所有em标签替换为i标签?

结果我需要:

    "<p>Some text <i>Italic string</i> ... </p><i>Second str</i>"

1 个答案:

答案 0 :(得分:0)

var replaceTag = "<p>Some text <em>Italic string</em> ... </p><em>Second str</em>";
replaceTag = replaceTag.replace(/<em>/g, "<i>");
replaceTag = replaceTag.replace(/<\/em>/g, "</i>");
console.log(replaceTag);