<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是模拟实际情况不要说去掉哦
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是模拟实际情况不要说去掉哦
ie6有问题
style="width:auto; height:auto;"
应该每次载入都是自动调整
但ie6却在第一次载入后就不会再调整了
如果不要css就会按
<style>
img{width:100px; height:100px;}
</style>
这个了
我这个是假设有外部样式的时候
<style>
img{width:100px; height:100px;}
</style>
,当图片小于这个大小的时候,就会被拉伸,变的很丑~强行定义了宽度和高度的话,再去获取图片真实大小就没意义了~
我这是假设有外部css设置了img的style
假设外部css设置了图片的大小,你动态加载的图片被定制成了固定的大小,而此时你想获得该图片的真实大小?是这个意思么?
那如下代码就可以获得图片真实大小。
function checkImg(theURL){
var width,height;
imgObj = new Image();
imgObj.src = theURL;
width=imgObj.width;
height=imgObj.height; return "w:"+width+",h:"+height;
}
用Image就不用插到body中了
试试