当我尝试为span元素创建类名时,会收到错误。
var regex = new RegExp("(" + input + ")", "im");
str = str.replace(regex, ("<span class="name">$1</span>"));
答案 0 :(得分:1)
退出中的“字符
var input = 'i';
var str = 'kaixo';
var pattern = new RegExp("(" + input + ")", "gim");
str = str.replace(pattern, ("<span class=\"target\">$1</span>"));
console.log(str);
输出:
ka<span class="target">i</span>xo