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;
}
});
});
HTML代码页面加载
<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>
过程中没有的高度和在IE中的图像的宽度我有问题,这个代码在IE中。在这里,我设置了运行时图像的高度和宽度(页面加载事件 - 使用jQuery)以及使用代码隐藏的图像源。
此代码工作得很好,除了IE8所有的浏览器。在页面加载事件中,我得到了图像的高度和宽度,但我没有得到IE8中图像的高度和宽度。我在加载事件中尝试了很多以获取图像的高度和宽度,但它不起作用。
有谁知道解决方案吗?
你试过用'$(本).height()'和'$(本).WIDTH()'?这应该可以。 – ubik
是的..我试了它,但它不工作。我得到0(零)作为高度和宽度 – ravidev
这将是很好有一个jsfiddle玩这个。您也可以尝试使用'jQuery(“。extraimgs”).load(function(){/ * ... * /})',因为图像在代码执行时尚未加载。 – ubik