jQuery 1.8的外部高度/宽度不起作用 [英] jQuery 1.8 outer Height/Width not working
问题描述
我在很多地方都使用过outerHeight
和outerWidth
.现在,在jQuery 1.8发布之后,我遇到了很多由对象返回而不是对象大小引起的问题.
I have used outerHeight
and outerWidth
on many places. Now, after jQuery 1.8 was released I have met a lot of issues caused by object return instead of its size.
例如:
$('#stackoverflowdiv').Height() // returns 100 px
$('#stackoverflowdiv').outerHeight() // returns "stackoverflowdiv" div
我发现解决此问题的唯一方法是在函数中使用"true/false",如下所示,但得到的结果与标准width()
和height()
函数相同:
The only thing that I have found to fix this was to use "true/false" in the function as follows but the I get the same results as the standard width()
and height()
functions:
$('#stackoverflowdiv').outerHeight(true) // returns 100 px
$('#stackoverflowdiv').outerHeight(false) // returns 100 px
有人知道为什么这种方法不能再起作用了,或者无法以其他方式获取元素的高度/宽度及其边距.
Has anyone knew why this is not working any more or other way to get the height/width of element + its margins.
我开始相信这是由于使用contents()
函数在iframe中选择元素而引起的.我将尝试进行演示.
I started to believe that this is caused because I am selecting elements in iframe using contents()
function. I will try to make a demo.
推荐答案
This is actually a known jQuery bug that you can read about here.
我没有参数,并且修复程序正在设置参数(即使有默认的{false}),但我能够通过将true参数替换为1并将false替换为0来打破Barlas的小提琴.因此,如果您愿意,请不要这样做.
I'm experiencing it with no parameter and the fix is setting the parameter (even though there's a default {false}), but I was able to break Barlas' fiddle by replacing the true parameter with 1 and false with 0. So don't do that if you are.
执行此操作:
alert(jQuery(this).outerHeight(false));
不要这样做:
alert(jQuery(this).outerHeight());
alert(jQuery(this).outerHeight(0));
这篇关于jQuery 1.8的外部高度/宽度不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!