相当于 getcomputedstyle() 的 jquery

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19137507/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 23:16:34  来源:igfitidea点击:

jquery equivalent for getcomputedstyle()

javascriptjqueryfunction

提问by Arun P Johny

I found this getComputedStyle polyfill in a JavaScript plugin

我在JavaScript 插件中发现了这个 getComputedStyle 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;
  };
}

Is there any jQuery equivalent for getcomputedstyle();

是否有任何 jQuery 等效的 getcomputedstyle();

回答by Arun P Johny

You can use the getter version of .css().

您可以使用.css()的 getter 版本。

From doc

来自文档

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.

.css() 方法是从第一个匹配元素获取样式属性的便捷方法,特别是考虑到浏览器访问大多数这些属性的不同方式(基于标准的浏览器中的 getComputedStyle() 方法与 currentStyle 和 runtimeStyle Internet Explorer 中的属性)以及浏览器对某些属性使用的不同术语。

like

喜欢

$(el).css('color')