亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

關于創建屬性節點的問題

a是一個標簽,有三種創建屬性的方式

//a.color="blue";可以

a.setAttribute("color","blue");//可以

//var attribute=document.createAttribute("color");//返回是一個屬性節點

//attribute.value="blue";

//a.appendChild(attribute);//這種方式明顯不行

//那么如何將attribute放到a標簽中?????


正在回答

1 回答

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等)

1 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
JavaScript進階篇
  • 參與學習       468832    人
  • 解答問題       22582    個

本課程從如何插入JS代碼開始,帶您進入網頁動態交互世界

進入課程

關于創建屬性節點的問題

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號