简体   繁体   English

通过DOM访问float属性

[英]Accessing float property through DOM

I have a DOM element that in Firebug clearly shows a float: left property. 我有一个DOM元素,该元素在Firebug中清楚地显示了float: left属性。 But when I process it in the DOM, element.style.float returns undefined . 但是当我在DOM中处理它时, element.style.float返回undefined

Am I just overlooking something on my end (this is what I'm assuming right now) or is there a special way to address float ? 我是只是忽略了某些事情(这就是我现在所假设的),还是有一种特殊的方法来处理float I would be baffled if there were. 如果有的话,我会感到困惑。

element.style.cssFloat (styleFloat in IE) uses a convention of the browsers to assign attributes as property names in the html engine. element.style.cssFloat(IE中的styleFloat)使用浏览器的约定将属性分配为html引擎中的属性名称。 Sometimes they work, other times not. 有时它们起作用,而其他时候则不起作用。 keywords can't be property names in a script- class, for, float become className, htmlFor, cssFloat or styleFloat. 关键字不能是脚本类中的属性名称,因为float变为className,htmlFor,cssFloat或styleFloat。

The dom syntax is: element.style.getPropertyValue('float'), but that will only work for inline style assignments. dom语法为: element.style.getPropertyValue('float'),但这仅适用于内联样式分配。

To get any stylesheet defined style you must look deeper: 要获取任何样式表定义的样式,您必须深入了解:

document.defaultView.getComputedStyle(element,'').getPropertyValue('float'); document.defaultView.getComputedStyle(element,'')。getPropertyValue('float');

Note- this is for firefox, opera, chrome, safari. 注意-这适用于Firefox,Opera,Chrome和Safari。 IE has its own methods for style look ups. IE具有自己的样式查找方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM