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