clientWidth和clientHeight返回0 [英] clientWidth and clientHeight returns 0

查看:987
本文介绍了clientWidth和clientHeight返回0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么clientWidth / Height在IE,Chrome和Safari上返回0?但在Firefox和Opera上运行良好。
我使用了下面的代码:

$ $ $ $ $ $ $ $ $ $(document).ready(function(){
$ b (var i = 0; i< = imgLength - 1; i ++)$ b var imgs = document.getElementsByTagName('img');
var imgLength = imgs.length;

{

var imgWidth = imgs [i] .clientWidth;
var imgHeight = imgs [i] .clientHeight;

'('img')。eq i).attr({
width:imgWidth,
height:imgHeight
});

console.log(imgWidth);
}

console.log(imgLength);

});

有什么想法吗?感谢。



我用window.load与clientwidth一起试用,它对Firefox,Chrome和Opera的工作正常,但他其他人没有

解决方案

尝试更改doctype。

http://forums.asp.net/post/1515655.aspx

我不确定,但我解决了这个问题。


Why clientWidth/Height return 0 on IE, Chrome and Safari? but on Firefox and Opera works fine. I used this code:

$(document).ready(function () {

    var imgs = document.getElementsByTagName('img');
    var imgLength = imgs.length;

    for (var i = 0; i <= imgLength - 1; i++) {

        var imgWidth = imgs[i].clientWidth;
        var imgHeight = imgs[i].clientHeight;

        $('img').eq(i).attr({
            width: imgWidth,
            height: imgHeight
        });

        console.log(imgWidth);
    }

    console.log(imgLength);

});

any idea? Thanks.

I tried with window.load with clientwidth its works fine for Firefox, Chrome and Opera but he others not

解决方案

Try change doctype.
http://forums.asp.net/post/1515655.aspx
I'm not sure, but I solved this problem so.

这篇关于clientWidth和clientHeight返回0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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