Dom 結(jié)點創(chuàng)建 基礎(chǔ)知識
更新時間:2011年10月01日 00:41:14 作者:
節(jié)點操作基礎(chǔ)知識回顧,需要dom操作的朋友可以參考下。
復(fù)制代碼 代碼如下:
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);
}
相關(guān)文章
javascript拓展DOM操作 prependChild insertAfert
Javascript dom操作中有appendChild 和insertBefore 卻沒有prependChild 和insertAfter2010-11-11