原生JS添加HTML元素或者TEXT文本

方法:

  • insertAdjacentHTML(postion,html);

  • insertAdjacentTEXT(postion,text);

参数:

position 是相对于 element 元素的位置,并且只能是以下的字符串之一:

  1. beforeBegin: 插入到标签开始前
  2. afterBegin:插入到标签开始标记之后
  3. beforeEnd:插入到标签结束标记前
  4. afterEnd:插入到标签结束标记后
  5. html 是 需要添加的标签节点
  6. text 是文本

猜你喜欢

转载自blog.csdn.net/blue_698/article/details/112695033
今日推荐