jQuery 1.8的外部高度/宽度不起作用 [英] jQuery 1.8 outer Height/Width not working

查看:86
本文介绍了jQuery 1.8的外部高度/宽度不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在很多地方都使用过outerHeightouterWidth.现在,在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.

推荐答案

这实际上是一个已知的jQuery错误,您可以阅读有关

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆