开发者

jquery, images type

开发者 https://www.devze.com 2022-12-12 15:15 出处:网络
I\'dlike 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\"/>

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

精彩评论

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