jquery, images type
I'd like to change image type with jquery, for example:
<img width="250" height="61" alt="Stack Overflow" src="http:/开发者_如何学JAVA/sstatic.net/so/img/logo.png"/>
to
<a href="/"><img width="250" height="61" alt="Stack Overflow" src="http://sstatic.net/so/img/logo.gif"/></a>
To change ".png: in ".gif" (in this case)
Thanks !
This should work:
$('img').each(function()
{
this.src = this.src.replace(/png$/, '.gif');
});
Try this: (Assuming that all .png
images have equivalent .gif
images on the server)
$('img[src$=".png"]').each(function(img) {
img.attr('src', img.attr('src').replace(/\.png$/, '.gif'));
});
精彩评论