为什么当我尝试以下操作时 jQuery 返回速记 CSS:
alert($('#t1').attr('style'));
在这个 html 上:
<div id="t1" style="border-style: solid; border-width: 10px; border-color: red; height: 100px; width: 100px;">Hello</div>
它返回:
border: 10px solid red; height: 100px; width: 100px;
这发生在 firefox 中。不在 chrome 中。
我怎样才能准确地获得样式属性的内容?
这是一个complete test .
最佳答案
你想做什么?很难看到你想要什么。
就是说,如果你使用纯 js 会发生什么,比如
(function getStyles(){
var styles = document.getElementById("t1").getAttribute("style");
alert(styles);
})();
关于javascript - jQuery 返回样式属性的简写 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8055262/