jQuery - css()在firefox中无法正常工作 [英] jQuery - css() not working properly in firefox
问题描述
我正在使用 .css()
从元素中获取样式。
但是在firefox .css()
中没有得到 margin
和的值从元素填充
。
I am using .css()
to get style from a element.
But in firefox .css()
is not getting value of margin
and padding
from element.
请看小提琴:
http://jsfiddle.net/howtoplease/fMTsW/
这是我的jquery代码:
$(document).ready(function(){
$('input').each(function(){
this.value = $('h3').css(this.name);
});
});
我的HTML代码
<h3 style="margin:20px;padding:20px;font-size:30px;font-family:'open sans';">
I am heading 3
</h3>
<input name="margin" />
<input name="padding" />
<input name="font-size" />
<input name="font-family" />
推荐答案
CSS标签'margin& padding'实际上是四个单独的margin / padding值的简写,top / left / bottom / right。使用css('marginTop')等 - 请注意,如果您已经指定了它们,它们将在末尾有'px'。
The CSS tag 'margin & padding' is actually a shorthand for the four separate margin/padding values, top/left/bottom/right. Use css('marginTop'), etc. - note they will have 'px' on the end if you have specified them that way.
使用parseInt()结果将其变为数字值。
Use parseInt() around the result to turn it in to the number value.
<input name="margin-top" />
<input name="padding-top" />
OR
<input name="marginTop" />
<input name="paddingTop" />
这将为您提供价值。使用这种技术,您可以获得保证金和填充的价值。
This will give you the value. Using this technique you can get the value of margin and padding.
这篇关于jQuery - css()在firefox中无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!