Dom 结点创建【基础知识】

节点操作基础知识回顾:

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);
}



posted @ 2011-09-30 16:44  wkylin  阅读(360)  评论(1编辑  收藏  举报