运行时如何解决此代码错误?
var replaced = $("body").html().replace(/<td>YES</td>/g,'<span class="yes"></span>');
$("body").html(replaced);
我想替换所有
<td>YES</td>
带
<span class="yes"></span>
答案 0 :(得分:1)
考虑:
$("td").filter(function() {
return $(this).text() === 'YES';
}).replaceWith('<span class="yes"></span>');
这会找到td
作为唯一内容的所有YES
元素和过滤器,并替换它们。
答案 1 :(得分:0)
尝试在表达式
中使用转义字符表示结束tdvar replaced = $("body").html().replace(/<td>YES<\/td>/g,'<span class="yes"></span>');
$("body").html(replaced);