首页 > 编程 > JavaScript > 正文

Dom 结点创建 基础知识

2019-11-20 23:39:05
字体:
来源:转载
供稿:网友
复制代码 代码如下:

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);
}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表