简体   繁体   English

如何解决脚本的无效正则表达式标志?

[英]How to solve script's Invalid regular expression flags?

How can I solve this code error when running! 运行时如何解决此代码错误!

 var replaced = $("body").html().replace(/<td>YES</td>/g,'<span class="yes"></span>'); $("body").html(replaced); 

I want to replace all 我要全部替换

<td>YES</td>

with

<span class="yes"></span>

Consider: 考虑:

$("td").filter(function() {
    return $(this).text() === 'YES';
}).replaceWith('<span class="yes"></span>');

This finds all the td elements and filters for the ones with YES as the only contents and the replaces them. 这将查找所有td元素,并过滤那些以YES为唯一内容的元素,并将其替换。

try to use an escape character for the closing td in your expression 尝试在表达式的结尾td中使用转义字符

var replaced = $("body").html().replace(/<td>YES<\/td>/g,'<span class="yes"></span>');
$("body").html(replaced);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM