当前位置:Gxlcms > JavaScript > Dom结点创建基础知识_DOM

Dom结点创建基础知识_DOM

时间:2021-07-01 10:21:17 帮助过:24人阅读

代码如下:

var body = document.body;
var html = document.documentElement;
var div = document.createElement("div");
var p = document.createElement("p");
var ali = document.createTextNode("alipay");
p.appendChild(ali);
div.appendChild(p);
div.setAttribute("id","fn-div");
div.setAttribute("class","fn-class");
body.appendChild(div);

var arr = div.attributes;
for(var i=0;iconsole.log(arr[i].name + ":" + arr[i].value);
}

人气教程排行