`
lushuaiyin
  • 浏览: 673047 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

js中insertAdjacentHTML函数在元素标签的前中后插入html代码

 
阅读更多

Adajcent 邻近的

原型:insertAdajcentHTML(swhere,stext)

insertAdjacentHTML方法:在指定的地方插入html标签语句
参数:
swhere: 指定插入html标签语句的地方,有四种值可用:
1.beforeBegin: 插入到标签开始前

2.afterBegin:插入到标签开始标记之后

3.beforeEnd:插入到标签结束标记前

4.afterEnd:插入到标签结束标记后

stext:要插入的内容



<head>
<title>insertAdjacentHTML插入新内容</title>
<script language="jscript">
function addwenzi()
{
document.all.dd.insertAdjacentHTML("afterBegin","<h1>hh11在第一个div后边(div内)插入内容</h1>");
document.all.dd.insertAdjacentHTML("beforeEnd","<h2>hh222在第二个div前边(div内)插入内容</h2>");
document.all.dd.insertAdjacentHTML("beforeBegin","<h4>hhh444在第一个div前边插入内容</h1>");
document.all.dd.insertAdjacentHTML("afterEnd","<h5>hh555在第二个div后边(div外)插入内容</h2>");
}
</script>
</head>
<body onload="addwenzi()">
第一个div前边beforeBegin(div外)<div id="dd" style="fontsize:6;color='#ff00ff'">第一个div后边afterBegin(div内),
;第二个div前边beforeBegin(div内)</div>第二个div后边afterEnd(div外)<hr>

<a href=""><u> <font color="red">This is some text!</font></u></a>
</body>
</html>



刚看这个函数说明的时候一头雾水,看效果就知道什么意思了



分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics