是否有一种简单的跨浏览器方法可以获取 PrototypeJS 中元素的计算样式,而无需检查 document.defaultView... 和其他属性? ...这样代码看起来像
var elt = $$('.xyz')[k],
border = elt.getComputedStyle('border-bottom-width')
PrototypeJs 提供了 getDimensions
、-Width
和 -Height
方法来返回计算尺寸,但没有获取其他计算样式的方法,例如边框、背景等。
我发现了几个独立的implementations getCompatedStyle,但也许 PrototypeJS 有一个补丁/插件可以做到这一点?
最佳答案
原型(prototype)的getStyle
方法封装了您正在寻找的大部分跨浏览器计算样式工作:
var bgColor = $(element).getStyle('background-color');
来自文档:
This method looks up the CSS property of an element whether it was applied inline or in a stylesheet. It works around browser inconsistencies regarding float, opacity, which returns a value between 0 (fully transparent) and 1 (fully opaque), position properties (left, top, right and bottom) and when getting the dimensions (width or height) of hidden elements.
但是,此方法不会返回 Internet Explorer <= 8 中样式表中应用的样式,因为它使用 getCompulatedStyle() 方法,该方法对于版本 8 及更低版本来说是不正确的方法:http://www.quirksmode.org/dom/w3c_css.html
关于javascript - Prototype JS 中的简单 getCompulatedStyle?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2056252/