<style>
img{width:100px; height:100px;}
</style>
<img id="tt" style="width:auto; height:auto;" />
<script>tt.onload = function(){ this.onload=null; this.src = "http://www.baidu.com/img/lm.gif" }tt.src = "http://www.baidu.com/img/baidu_logo.gif"</script>这个在ie7 8 都没问题
在ietester的ie6就不正常(宽高在第一次载入就定死了)
怎么解决
ps:style是模拟实际情况不要说去掉哦

解决方案 »

  1.   

    应该是样式冲突了,用DEVELOPTOOLBAR调试看看
      

  2.   

    自身的style优先级高于css,<img id="tt" style="width:auto; height:auto;" />
      

  3.   

    css可以控制页面上所有应用了该样式的元素,但是如果该元素自己定义了style,则以自身style优先
      

  4.   

    我不是说style的问题而是兼容问题
    ie6有问题
      

  5.   

    设置了
    style="width:auto; height:auto;" 
    应该每次载入都是自动调整
    但ie6却在第一次载入后就不会再调整了
      

  6.   

    可以的话还是都用js来控制吧~~去掉style样式~~貌似是IE6的bug
      

  7.   

    不给img加任何样式,连css中都不要去控制,就能获得真实图片的大小的。tt.offsetWidth,tt.offsetHeight
      

  8.   


    如果不要css就会按
    <style>
    img{width:100px; height:100px;}
    </style>
    这个了
    我这个是假设有外部样式的时候
      

  9.   

    我就是说连这个style都不要,img自身也不要去设置style的width和height你用了
    <style> 
    img{width:100px; height:100px;} 
    </style> 
    ,当图片小于这个大小的时候,就会被拉伸,变的很丑~强行定义了宽度和高度的话,再去获取图片真实大小就没意义了~
      

  10.   

    你误会了
    我这是假设有外部css设置了img的style
      

  11.   

    有点迷糊了~~
    假设外部css设置了图片的大小,你动态加载的图片被定制成了固定的大小,而此时你想获得该图片的真实大小?是这个意思么?
    那如下代码就可以获得图片真实大小。
    function checkImg(theURL){
        var width,height;
        imgObj = new Image();
        
        imgObj.src = theURL;
        
        width=imgObj.width;        
        height=imgObj.height;    return "w:"+width+",h:"+height;
      

  12.   

    对哦
    用Image就不用插到body中了
    试试