我在 JavaScript plugin 中找到了这个 getCompulatedStyle polyfill
if (!computed) {
window.getComputedStyle = function(el) {
this.el = el;
this.getPropertyValue = function(prop) {
var re = /(\-([a-z]){1})/g;
if (prop === "float") {
prop = "styleFloat";
}
if (re.test(prop)) {
prop = prop.replace(re, function () {
return arguments[2].toUpperCase();
});
}
return el.currentStyle[prop] ? el.currentStyle[prop] : null;
};
return this;
};
}
是否有与 getcompulatedstyle() 等效的 jQuery;
最佳答案
您可以使用 .css() 的 getter 版本.
来自文档
The .css() method is a convenient way to get a style property from the first matched element, especially in light of the different ways browsers access most of those properties (the getComputedStyle() method in standards-based browsers versus the currentStyle and runtimeStyle properties in Internet Explorer) and the different terms browsers use for certain properties.
喜欢
$(el).css('color')
关于javascript - jquery 相当于 getcompulatedstyle(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19137507/