首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

Jquery 如何在ie6和chrome里获取一张图片的宽度跟高度

2013-11-21 
Jquery 怎么在ie6和chrome里获取一张图片的宽度跟高度?谢谢!div idaaa/divdiv idccc styledi

Jquery 怎么在ie6和chrome里获取一张图片的宽度跟高度?
谢谢!Jquery 如何在ie6和chrome里获取一张图片的宽度跟高度

<div id="aaa"></div>
<div id="ccc" style="display:none;"><img src="http://www.csdn.net/css/logo.png" id="eee" /></div>
<script language="javascript">
$(document).ready(function(){
   var theImage = new Image();
   var iurl = $("#eee").attr("src");
   var fk = 0,fg = 0;
   theImage.src = iurl;
   $("#aaa").load(iurl,function(){
      fk = theImage.width;
      fg = theImage.height;
      if(fk == 0){
         fk = 500;
         fg = 300;
      };
   };
   $("#aaa").html(fk);
});
</script>

[解决办法]
var theImage = new Image();
   var iurl = $("#eee").attr("src");
   var fk = 0,fg = 0;
theImage.onload=function(){
 fk = this.width;
      fg = this.height;
alert(fk+" "+fg);
};
   theImage.src = iurl;
[解决办法]
(document).ready(function(){
   var img = $('#eee');
   if(img[0].width){
       $("#aaa").html(img[0].width); 
   }else{
       img[0].onload = function(){
         $("#aaa").html(img[0].width);    
       }
   }
});
[解决办法]

var screenImage = $(this).find('img');
                theImage.src = screenImage.attr("src");
                var imageWidth = theImage.width;
                var imageHeight = theImage.height;

[解决办法]
  $(document).ready(function () {
        var theImg = new Image();
        theImg.src = $("#aaa").attr("src");
        var ss = $("#aaa").attr("height");
        alert(theImg.width+"=="+theImg.height);
    });

热点排行
Bad Request.