dom创建新节点的方法

 时间:2026-05-04 04:15:15

1、//创建一个新节点

var  pNode=  document.createElement("p");

2、//创建文本

var pText=  document.createTextNode("hello"); 

3、//将文本添加至创建的P节点中

pNode.appendChild(pText); 

4、//将pNode节点添加到Body节点中

document.body.appendChild(pNode); 

5、节点操作方法有,使用方法如上

appendChild()

removeClild()

replaceChild()

insertBefore()

1、jQuery中也有操作Dom节点的方法

//追加方法

$(".className").append("<b>你好!</b>");  //将B标签追加至节点中

2、$(".className").prepend("<b>你好!</b>");  //前置方法。insertBefore()

3、$(".className").after("<b>你好!</b>");

4、append()

appendTo()

prepen()

prepenTo()

after()

insertAfter()

before()

insertBefore()

  • 江湖悠悠怎么采摘水果
  • 江湖悠悠竹林七贤枯木位置
  • 江湖悠悠芝麻怎么获得
  • 《天命奇御》:前往杭州:水脉迷宫
  • 天命奇御深海玄铁怎么获得?
  • 热门搜索
    inch是什么单位 喉咙有痰是什么原因造成的 赏析是什么意思 什么是质量 psd是什么意思 独在异乡为异客的异是什么意思 缘分是什么 sex什么意思 urban是什么舞种 女生的胸长什么样