setAttribute(),既可以增加新的属性名称和值,也可以为已经存在的属性设置值。
例如:
可以为已经存在的属性设置值:
div1=document.createElement("div");
div1.setAttribute("width","600px");
也可以增加新的属性和值:
d1 = document.createElementNS("http://www.w3.org/2000/svg","rect");
d1.setAttribute("id",Datass[i].id);
d1.setAttribute("floorNo",Datass[i].floorNo);