jquery – 不能在chrome中获得真实的高度/宽度的对象

我有一个问题,如果我在css中设置一个图像高度,并尝试获得高度/宽度,我得到不同的结果在不同的浏览器.有没有办法在所有浏览器中获得相同的维度?

您可以找到一个实例here< -Removed 这个概念是这样的:

CSS:
img{
  height:100px;
  }

Script:
$(document).ready(function(){
    $("#text").append($("#img_0").attr("height"));
    $("#text").append($("#img_0").attr("width"));
});

输出Firefox:
img height:100
img width:150

输出Chrome:
img height:100
img width:0

输出Chrome:
img height:100
img width:93?

我已经尝试从StackOverflow:
stackoverflow.com/questions/1873419/jquery-get-height-width

但仍然得到相同的结果

任何一个人都知道一个很好的解决方案?

解决方法

图像没有在document.ready中加载,您需要使用window.load事件来确保它们存在,如下所示:
$(window).load(function(){
    $("#text").append($("#img_0").height());
    $("#text").append($("#img_0").width());
});

Here’s a quick read on the difference,重要的部分是图片被加载.

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...