jquery替换网页body中所有的“黑龙江”为“北京”,“黑龙江”可能是在不同的标签,不同的
中,请问如何写代码?需要完整代码,谢谢了!
jquery替换网页body中所有的“黑龙江”为“北京”,“黑龙江”可能是在不同的标签,不同的
<!DOCTYPE html>
<html>
<head>
<script src="/jquery/jquery-1.11.1.min.js">
</script>
<script>
$(document).ready(function(){
$("p").click(function(){
$(this).hide();
});
});
function replaceStr(){
// $('body')[0].innerHTML = $('body')[0].innerHTML.replace(/\黑龙江/g,'北京');
$('body').html($('body').html().replace(/\黑龙江/g,'北京'));
}
</script>
</head>
<body>
<p>如果黑龙江您点击我,我会消失。</p>
<p>点击我,黑龙江我会消失。</p>
<p>也要点击我哦。黑龙江</p>
黑龙江
<button onclick='replaceStr()'>替换</button>
</body>
</html>