insertAdjacentHTML 与 insertAdjacentText

来源:互联网 发布:淘宝运费险一般退多少 编辑:程序博客网 时间:2024/06/05 15:57

插入HTML内容与文本内容,功能上与innerHTML和innerTEXT相同。
insertAdjacentHTML 与 insertAdjacentText的用法完全相同,不同之处就是 insertAdjacentText插入的是单纯的文本信息
用法:

element.insertAdjacentHTML(position, String);

参数position的取值:

  • beforeBegin:在该元素前插入(元素外)
  • afterBegin:在该元素第一个子元素前插入(元素内)
  • beforeEnd:在该元素最后一个子元素后面插入(元素内)
  • afterEnd:在该元素后插入(元素外)


    For Example

var log = document.getElementById('log');log.insertAdjacentHTML('beforeEnd', 'this Is I want add <button type="button">ClickMe</button>');
0 0
原创粉丝点击