http://blog.sina.com.cn/s/blog_8ee552f30101en05.html
https://www.cnblogs.com/linxixinxiang/p/11315615.html
jquery 查找指定字符串元素對象實例:
:contains(text)匹配包含給定文本的元素
HTML 代碼:
jQuery 代碼:
$("div:contains('John')")
//通過Id
$("#showContent:contains('John')").html($("#showContent:contains('John')").html().replace(/John/g, "<img src=\"\" alt=\"\"/>"));
//通過class 可批量替換
$(document).ready(function(){
$(".intro").filter(":contains('is')").each(function() {
$(this).html($(this).html().replace("is", "are"));
});
});
var a='12,13,14,15';現在想把字符串替換,號為-
jquery中的replace方法:a.replace(",","-");只能替換掉第一個,號。即,結果為12-13,14,15
jquery中是沒有對字符串進行replaceAll的方法,通常這個時候,全部替換采用正則表達式的方式替換。如下:
var reg = new RegExp(",","g");//g,表示全部替換。
a.replace(reg,"-");
結果:12-13-14-15
------------------
結合以上兩篇文章,寫成我自己的:
把頁面上的 gt; 轉成 > 需要反斜杠轉義
var reg = new RegExp(" gt\;","g");//g,表示全部替換。
$(".p_coten").filter(":contains('gt\;')").each(function() {
//console.log("contains gt\;!");
$(this).html($(this).html().replace(reg, "\> "));
});