IE 7 中的 h2outerWidth 比 IE 8 短
今天我在项目中实施修正时遇到了一个问题。
我发现 IE 7 中 h2 的外宽度比 IE8(FF、Chrome 等)中的短。
这是我的代码:
var h2width = $('.test h2').outerWidth(true)
h2width 在 IE8 中为 135px,在 IE7 中为 78px。
你对此有什么想法吗?
提前致谢!
编辑:
为了防止这个问题,我添加了区分浏览器的代码。
if ($.browser.msie && $.browser.version.substr(0, 1) <= 7) {
var h2width = $('.test h2').outerWidth(true) + 57;
} else {
var h2width = $('.test h2').outerWidth(true);
}
I have encountered a problem today when i imeplement a correction in our project.
What i found is that the outerWidth for h2 in IE 7 is shorter than in IE8 (FF, Chrome etc).
Here is my code:
var h2width = $('.test h2').outerWidth(true)
h2width is 135px in IE8 and 78px in IE7.
Do you have any ideas for that?
Thanks in advance!
Edit :
For prevent this problem, i have added the code for differenciate the browsers.
if ($.browser.msie && $.browser.version.substr(0, 1) <= 7) {
var h2width = $('.test h2').outerWidth(true) + 57;
} else {
var h2width = $('.test h2').outerWidth(true);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
浏览器渲染 HTML 的方式不同,所以这并不奇怪。
使用Firebug或其他开发工具查看
h2
标签的实际大小。它们很可能是不同的。另请注意,您的选择器
$('.test h2')
返回匹配元素的集合。Browsers render HTML differently so this isn´t that strange.
Use Firebug or other development tool to view the actual size of your
h2
tag. They are most likely different.Also notice that your selector
$('.test h2')
returns a collection of matched elements.