我需要使用 jquery 和 javascript 替换 DOM(内存中的网页)中的所有单词。我需要改变这个:
<html>
<head>
Hi to all
</head>
<body>
Hi to all
</body>
</html>
进入这个:
<html>
<head>
Bye to all
</head>
<body>
Bye to all
</body>
</html>
但不修改标签(只有那里的值)
一种尝试是:
jQuery.fn.replaceEachOne = function (objective, rep) {
return this.each( function(){
$(this).html( $(this).html().replace( new RegExp('(\\s'+objective+'\\s(?![[\\w\\s?&.\\/;#~%"=-]*>]))', "ig"), rep) );
}
);
}
但是如果我放它,它会继续替换标签值并破坏页面。
帮助!!!