[英]How to solve script's Invalid regular expression flags?
運行時如何解決此代碼錯誤!
var replaced = $("body").html().replace(/<td>YES</td>/g,'<span class="yes"></span>'); $("body").html(replaced);
我要全部替換
<td>YES</td>
與
<span class="yes"></span>
考慮:
$("td").filter(function() {
return $(this).text() === 'YES';
}).replaceWith('<span class="yes"></span>');
這將查找所有td
元素,並過濾那些以YES
為唯一內容的元素,並將其替換。
嘗試在表達式的結尾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.