#elem {
-myCustom: 99;
}
或者
#elem {
--myCustom: 99;
}
我在网上看到这两种用例,它们之间有什么区别?
试图在JavaScript中访问自定义属性返回null。
#elem {
-myCustom: 99;
}
<div id="elem">some text</div>
elem = document.getElementById("elem");
style= window.getComputedStyle(elem);
value = style.getPropertyValue('-myCustom');
alert(value);
-myCustom: 99;
是无效的,并且(大多数)Web浏览器将忽略它。(我也确定它与任何类型的浏览器黑客无关)。 - Hashem Qolami