2013-02-05 85 views
1



有沒有辦法添加一個自定義的HTML屬性來說一個DIV元素,然後能夠在IE中使用CSS屬性選擇器?

例子工程(變爲綠色)的FF而不是在IE:
HTML自定義屬性和IE

在JavaScript:

element.setAttribute('newAttr', 'green'); 


在CSS:

[newAttr=green] { 
    background-color: green; 
} 


親切的問候

+0

http://stackoverflow.com/questions/710275/how-to-add-update-an-attribute-to-an-html-element-using -javascript 上面的鏈接是爲你提供答案... – Ksnrg

+0

@Ksnrg:我在訪問這些創造歸功於使用CSS屬性選擇在IE – geeko

回答

0

你可以這樣做:

<div id="some" data-newattr="green"></div> 
0
var attribute = document.createAttribute("size"); 
attribute.nodeValue = "15" 
document.getElementById("text").setAttributeNode(attribute); 
+0

出於某種原因很感興趣,我試過用CSS屬性選擇器在IE它不工作! – geeko