Chrome错误地报告了宽度和高度加载时间期间或之后的图像值。 Jquery在这个代码示例中使用:Google Chrome再次出错
<img id='image01' alt='picture that is 145x134' src='/images/picture.jpg' />
<script>
var img = $('img#image01')
img.width() // would return 145 in Firefox and 0 in Chrome.
img.height() // would return 134 in Firefox and 0 in Chrome.
</script>
如果你把这个脚本在$(function(){})
功能,结果是一样的。但是如果您在页面加载后几秒钟运行代码,则chrome会返回正确的结果。如果指定宽度和高度在IMG标签值
<script>
function example() {
var img = $('img#image01');
img.width() // returns 145 in both Firefox and Chrome.
img.height() // returns 134 in both Firefox and Chrome.
}
window.setTimeout(example, 1000)
</script>
此外,脚本似乎有望在这两个Firefox和Chrome工作。
<img id='image01' src='/images/picture.jpg' width=145 height=134 />
但是,因为您无法始终控制html输入,所以这不是一个理想的解决方法。 jQuery可以针对此问题采用更好的解决方法进行修补?或者我需要为我的代码中的每个图像指定宽度和高度?
现在这就是赞助标记是! – beggs 2010-06-14 08:07:42
@beggs ...我不遵循? – Stefan 2010-06-14 08:38:55