日期:2014-05-16 浏览次数:20456 次
<item text="a" id="1" >
<item text="a1" id="2"></item>
<item text="a2" id="3"></item>
....
</item>
<item text="ba1" ></item>
<item text="ba2" ></item>
<item text="a" id="1" >
<item text="ba1" ></item>
<item text="ba2" ></item>
</item>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<BODY>
<script type="text/javascript">
var tagContent = "<div>呵呵呵</div><div>哈哈哈</div>"
function replace(){
var superNod = document.getElementById("11").parentNode;
for(var i = superNod.childNodes.length - 1; i > 0; i--){
superNod.removeChild(superNod.childNodes[i]);
}
superNod.innerHTML = superNod.innerHTML + tagContent;
}
</script>
<div>
<div id="11">zhangsan</div>
<div name="ee">lisi</div>
<div name="bb">wangsu</div>
</div>
<input type="button" value="替换内容" onclick="replace()"/>
</BODY>
</HTML>
var html="";
html=html.replace(/(<item[^>]*?id=(['"]?)1\2\s*>)(\n<item[^>]*?>