Javascript 页面加载期间IE中没有图像的高度和宽度

Javascript 页面加载期间IE中没有图像的高度和宽度,javascript,jquery,asp.net,css,image,Javascript,Jquery,Asp.net,Css,Image,HTML代码 jQuery(window).load(function() { jQuery.each(jQuery(".extraimgs"), function() { //this.height = 0 and this.width=0 in IE only if (this.height > this.width) { if (this.height > 263) { this.h

HTML代码

jQuery(window).load(function() {
    jQuery.each(jQuery(".extraimgs"), function() {
        //this.height = 0 and this.width=0 in IE only
        if (this.height > this.width) {
            if (this.height > 263) {
                this.height = 263;
            }
            if (this.width > 354) {
                this.width = 354;
            }
        }
        else {
            this.height = 263;
            this.width = 354;
        }
    });
});

在IE中,我对这段代码有问题。在这里,我使用代码隐藏设置运行时图像的高度和宽度(页面加载事件-使用jQuery)和图像源

此代码在除IE8之外的所有浏览器中都能正常工作。在页面加载事件中,我得到了图像的高度和宽度,但在IE8中没有得到图像的高度和宽度。在加载事件期间,我尝试了很多方法来获取图像的高度和宽度,但都不起作用

有人知道解决方案吗?

关于
$(文档).load()
$(文档).ready()
而不是
$(窗口).load()

尝试以下方法:

<asp:DataList runat="server" ID="dlImages" RepeatColumns="2" RepeatDirection="Horizontal" RepeatLayout="Table" OnItemDataBound="dlImages_ItemDataBound" Style="display: none;">
    <ItemTemplate>
        <div>
            <asp:Image runat="server" ID="imgPics" class="extraimgs" />
        </div>
    </ItemTemplate>                                 
</asp:DataList>

好的,根据我上面的评论,这里有一个版本应该可以工作:

jQuery(document.body).load(function () {
      jQuery(".extraimgs").each(function (i) {
        if (this.height > this.width) {
            if (this.height > 263) {
                this.height = 263;
            }
            if (this.width > 354) {
                this.width = 354;
            }
        }
        else {
            this.height = 263;
            this.width = 354;
        }
      });
    });

您是否尝试过使用
$(this).height()
$(this).width()
?这应该可以。是的。我试过了。但它不起作用。我得到了0(零)的高度和宽度。如果有一个JSFIDLE来玩这个会很好。您也可以尝试执行
jQuery(“.extraimgs”).load(function(){/*…*/})
,因为在代码执行时,可能还没有加载图像。我已经阅读了,而且这应该可以工作,JSFIDLE链接将很好地使用。事实上,我没有注意到OP正在使用
.load()
。它不起作用。在这里,我不能用这个来计算高度和宽度
jQuery(function() {
    jQuery(".extraimgs").load(function() {
        var $this = $(this);
        if ($this.height > $this.width) {
            if ($this.height > 263) {
                $this.height = 263;
            }
            if ($this.width > 354) {
                $this.width = 354;
            }
        }
        else {
            $this.height = 263;
            $this.width = 354;
        }
    });
});