首页 > js/jquery批量替换HTML文本

js/jquery批量替换HTML文本

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>

DedeCMS推荐
织梦采集https链接时却生成http协...
织梦后台登录出现500错误解决方案
织梦首页调用自定义表单内容方法
织梦自定义表单地区联动类型不可用的解决办...
织梦模板文档关键词维护中频率详解
织梦后台栏目显示的文档数与实际文档数不一...