开发者

jQuery replace image source in IE

In the DOM 开发者_JS百科I am loading a static Google Map image. When the document is ready with jQuery sometimes I need to replace that image with a bigger version. Problem is that in IE the CPU goes whooooooo because IE is still looking to load the initial image with no success. Is there a way to cancel or clear the previous load?

EDIT: I should note that I use .html() inside a function when SWFObject is not successfully embedded..

I am not able to reproduce the problem in following example, but basically I use this:

JS:

$(document).ready(function() {
    $("img#myImage").html('<img id="myImage" src="images/002.jpg" />');
});

HTML

<img id="myImage" src="images/001.jpg" />


The .html() function replaces the HTML inside the img tag. Of course, there is no HTML in the img tag. Instead, use .attr():

$("img#myImage").attr('src', 'images/002.jpg');

Calling this immediately changes the source of the image and the browser should begin loading the new image.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜