复制代码 代码如下:
复制代码
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;i<arr.length;i++){
console.log(arr[i].name + ":" + arr[i].value);
}
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;i<arr.length;i++){
console.log(arr[i].name + ":" + arr[i].value);
}
最后
以上就是喜悦白开水最近收集整理的关于Dom 结点创建 基础知识的全部内容,更多相关Dom内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复