HTML DOM Yuanxiu insertAdjacentText() fangfa

dingyi he yongfa

insertAdjacentText() fangfa jiang wenzi ruxian zhi zhiding weizhi.

hege de weizhi:

zhi miaoshu
afterbegin zai yuanxiu kaishi zhi hou (di yi ge zi xu yuanshi).
afterend yuanxiu hou.
beforebegin yuanxiu qian.
beforeend zai yuanxiu jieshu zhi qian (zui hou ge zi xu yuanshi).

shi li

li ti 1

zai biaoti yuanxiu hou ruxian wenzi:

const h2 = document.getElementById("myH2");
let text = "My inserted text";
h2.insertAdjacentText("afterend", text);

zishen shi yi

li ti 2

shi yong "afterbegin":

const h2 = document.getElementById("myH2");
let text = "My inserted text";
h2.insertAdjacentText("afterbegin", text);

zishen shi yi

li ti 3

shi yong "beforebegin":

h2.insertAdjacentText("beforebegin", text);

zishen shi yi

li ti 4

shi yong "beforeend":

h2.insertAdjacentText("beforeend", text);

zishen shi yi

yufa

element.insertAdjacentText(weizhi, text)

haya

node.insertAdjacentText(weizhi, text)

canju

canju miaoshu
weizhi

yixu. Xiangdui yuanxiu de weizhi:

  • afterbegin
  • afterend
  • beforebegin
  • beforeend
text a baiya a ruxian.

sududu kai dake

kukun kai dake sujudu element.insertAjacentText()

Chrome IE Edge Firefox Safari Opera
Chrome IE Edge Firefox Safari Opera
Gudanarwa Gudanarwa Gudanarwa Gudanarwa Gudanarwa Gudanarwa