有没有办法使用jQuery从img scr扩展中删除?使用jQuery删除图像扩展
从这个意义上:
<img src="images/6208606.jpg" width="120" height="120" />
这样:
<img src="images/6208606" width="120" height="120" />
感谢您的帮助
有没有办法使用jQuery从img scr扩展中删除?使用jQuery删除图像扩展
从这个意义上:
<img src="images/6208606.jpg" width="120" height="120" />
这样:
<img src="images/6208606" width="120" height="120" />
感谢您的帮助
你可以这样做:
$('img').each(function(){
$(this).attr('src', $(this).attr('src').replace(/\.jpg/, ''));
});
如果你有你需要找你可以做多个扩展名:
var exts = ['.jpg', '.gif', '.png'];
$('img').each(function(){
var $t = $(this);
$.each(exts, function(i,v){
$t.attr('src', $t.attr('src').replace(v, ''));
});
});
您需要提供一些标识(如id,name,alt)或特定的类来使用jquery选择器来选择图像。
//using css class 'special' applied to images whose
//src we need to replace
var i=$('img.special');
var s = $(i).attr("src");
s = s.substring(0, s.lastIndexOf("."));
$(i).attr("src",s);