js/jquery批量替换HTML文本
栏目:DedeCMS 来源:网络 关注:0 时间:2019-08-25
Jquery写法(多个)
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/1.8.3/jquery.js"></script>
<script type="text/javascript">
//jquery 写法(多个)
$(document).ready(function(){
var aaa = $('#content').html().replace(/(中国|几天|田野)/g, function($0, $1) {
return {
"中国": "外国",
"几天": "很多天",
"田野": "织梦CMS"
}[$1];
});
$('#content').html(aaa);
});
</script>
js写法(单个)
<script type="text/javascript">
//js 写法(单个)
onload = function()
{
var content = document.getElementById("content");
content.innerHTML = content.innerHTML.replace(new RegExp('中国','g'),'外国');
content.innerHTML = content.innerHTML.replace(new RegExp('几天','g'),'很多天');
content.innerHTML = content.innerHTML.replace(new RegExp('田野','g'),'织梦CMS');
}
</script>
本文标题:js/jquery批量替换HTML文本
本文地址:http://www.q0738.com/dedecms/18565.html