insertAdjacentHTML 与 insertAdjacentText

插入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>');

猜你喜欢

转载自blog.csdn.net/qq_33619285/article/details/70211153