开发者

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'));
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜