【问题标题】:HTML Custom Attributes and IEHTML 自定义属性和 IE
【发布时间】:2013-01-20 04:50:34
【问题描述】:



有没有办法添加自定义 HTML 属性来表示 DIV 元素,然后能够在 IE 中使用 CSS 属性选择器?

在 FF 中有效但在 IE 中无效的示例(变为绿色):

在 JavaScript 中:

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


在 CSS 中:

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


亲切的问候

【问题讨论】:

标签: javascript jquery html css jquery-selectors


【解决方案1】:
var attribute = document.createAttribute("size");
attribute.nodeValue = "15"
document.getElementById("text").setAttributeNode(attribute);

【讨论】:

  • 出于某种原因,我尝试在 IE 中使用 CSS 属性选择器,但它不起作用!
【解决方案2】:

你可以这样做:

<div id="some" data-newattr="green"></div>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-17
    • 2011-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-09
    • 1970-01-01
    相关资源
    最近更新 更多