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>
刚看这个函数说明的时候一头雾水,看效果就知道什么意思了
分享到:
相关推荐
insertAdjacentHTML(swhere,stext) 参数: swhere:指定插入html标签语句的地方,有四种值可以用: 1.beforeBegin:插入到标签开始前 2.afterBegin:插入到标签开始标记后 3.beforeEnd:插入到标签结束标记前 4.afterEnd...
insertAdjacentHTML动态插入行[归类].pdf
在table中插入多行,能使用与insertAdjacentHTML相似的功能
对于div等元素来说,插入一段html是很容易的事情,但是对于表格来说就太难了。一般情况下,我们都是用appendChild的方式,一行行、一格格地添加,操作起来很繁锁。能不能拼一串字符,就能直接加入到表格中呢? 下面...
after(element, string) : 在元素之后插入 HTML 字符串。 before(element, string) : 在元素之前插入 HTML 字符串。 append(element, string) : 将 HTML 字符串附加到元素。 prepend(element, string) : 将 HTML...
innerText 属性在 IE 浏览器中可以得到当前元素过滤掉 HTML Tags 之后的文本内容,在某些时候还是比较有用。但类似的非标准属性/方法在其他浏览器中并不一定都得到支持。 类似的像 insertAdjacentElement ,...
最近发现各大类库都能利用div[removed]=HTML片断来生成节点元素,再把它们插入到目标元素的各个位置上。这东西实际上就是insertAdjacentHTML,但是IE可恶的innerHTML把这优势变成劣势。首先innerHTML会把里面的某些...
Mozilla中独有的读写器(defineGetter、defineSetter)以及可以给Element,Event等加上prototype原型,使得在IE里用的方法同样在Mozilla中可以适用,下面贴出常用的一些代码 例如 obj.insertAdjacentHTML, ...
在不使用预定义转义功能的情况下,我们将不允许分配(例如,对innerHTML)和调用(例如,对insertAdjacentHTML)。 转义函数必须使用模板字符串来调用。 函数名称被硬编码为Sanitizer.escapeHTML和escapeHTML 。 ...
HTML5 元素通用DOM接口 interface HTMLElement : Element { // DOM tree accessors NodeList getElementsByClassName(in DOMString classNames); // dynamic markup insertion attribute DOMString innerHTML; ...
在测试套件中对设置要声明HTML有用。安装npm install --save string-to-dom用法var stringToDom = require ( 'string-to-dom' ) ;// Add the <p> tag to the page (right after the <body> tag).// `message`...
在脚本中要用到两个函数:insertAdjacentHTML和removeChild,而恰好这两个函数在Firefox下都不能正常使用。几乎花费了一天的时候,在网上搜索着解决的方法,还好被找到了,也让我大松一口气。 具体两个函数是这样的...
Javascript小技巧一箩筐 事件源对象 event.srcElement.tagName event.srcElement.type 捕获释放 event.srcElement.setCapture(); event.srcElement.releaseCapture(); 事件按键 event.keyCode ...
主要介绍了js简单实现表单中点击按钮动态增加输入框数量的方法,涉及javascript鼠标点击事件及insertAdjacentHTML方法的相关使用技巧,需要的朋友可以参考下
JavaScript权威指南 犀牛书 Chapter 1. Introduction to JavaScript Section 1.1. JavaScript Myths Section 1.2. Versions of JavaScript Section 1.3. Client-Side JavaScript Section 1.4. JavaScript ...
如:<iframe style="visibility: visible" name="FrameId" width="100%" height="30%" src="NeedPrintedPage.asp"></iframe>下面的pringFrame js函数将只打印Iframe中的内容,可以直接引用使用,如printFrame(FrameId...
最近发现各大类库都能利用xxx[removed]=HTML片断来生成节点元素,再把它们插入到目标元素的各个位置上。这东西实际上就是insertAdjacentHTML,但是IE可恶的innerHTML把这优势变成劣势。
首先,要谢谢CSDN hbhbhbhbhb1021(天外水火(我要多努力))和cuixiping(无心)的提醒。我会抽空把IE专有的方法如:...行innerHTML和insertAdjacentHTML速度的测试,比均结果相差不会大于20ms(平均速度),在I