關(guān)于創(chuàng)建屬性節(jié)點的問題
a是一個標(biāo)簽,有三種創(chuàng)建屬性的方式
//a.color="blue";可以
a.setAttribute("color","blue");//可以
//var attribute=document.createAttribute("color");//返回是一個屬性節(jié)點
//attribute.value="blue";
//a.appendChild(attribute);//這種方式明顯不行
//那么如何將attribute放到a標(biāo)簽中?????
2018-12-21
a.style.color='red';
a.setAttribute('style','color:red');
color不是標(biāo)簽屬性,style是屬性,class是屬性? color:red 這是style的內(nèi)容? 而且appendChild是把元素放入另個元素中,不是把屬性放入元素中
var attribute=document.createAttribute("style");//注意這里?。?!
attribute.value="color:blue";//這才是style屬性的完整值;
a.appendChild(attribute);-------a.setAttributeNode(attribute);//這是給標(biāo)簽添加屬性(class,style,name,value,type等)