insertAdjacentHTML 方法:在指定的地方插入html标签语句原型:insertAdajcentHTML(swhere,stext)参数:swhere: 指定插入html标签语句的地方,stext:要插入的内容有四种值可用:1. beforeBegin: 插入到标签开始前2. afterBegin:插入到标签开始标记之后3. beforeEnd:插入到标签结束标记前4. afterEnd:插入到标签结束标记后<html>
<head>
<script>
function myfun(){
var obj = document.getElementById("btn1");
obj.insertAdjacentHTML("afterEnd","<br><input name="txt1">");
}
</script>
</head>
<body>
<input name="txt">
<input id="btn1" name="btn1" type="button" value="更多" click="myfun()">
</body>
</html>
<html>
<head>
<title>24.htm insertAdjacentHTML插入新内容</title>
<script>
function addsome()
{
document.all.paral.insertAdjacentHTML("afterBegin","<h1> 在文本前容器内插入内容1</h1>");
document.all.paral.insertAdjacentHTML("beforeEnd","<h2> 在文本后容器内插入内容2</h2>");
document.all.paral.insertAdjacentHTML("beforeBegin","<h4> 在文本前容器外插入内容4</h1>");
document.all.paral.insertAdjacentHTML("afterEnd","<h5> 在文本后容器外插入内容5</h2>");
}
</script>
</head>
<body onload="addsome()">
<div id="paral" style="fontsize:6;color='#ff00ff'" mce_style="fontsize:6;color='#ff00ff'">原来的内容</div><hr>
</body>
</html>
删除div中节点
<script type="text/javascript">
function clearText() {
var content=document.getElementById("content");
for (var i=content.childNodes.length-1;i>=0;i--) {
var childNode = content.childNodes[i];
content.removeChild(childNode);
}
}
</script>
<div id="content">
<h1>1</h1>
<h1>2</h1>
<h1>3</h1>
<h1>4</h1>
<h1>5</h1>
<h1>6</h1>
</div>
<button click="clearText();">清除节点内容</button>
该贴由koei123转至本版2015-7-26 22:50:07