使用jquery将所有图像src值从jpg修改为png

使用jquery将所有图像src值从jpg修改为png,jquery,Jquery,dom由img属性组成,如 <img src="http://example.com/cat.jpg" <img src="http://example.com/dog.jpg" <img src="http://example.com/rat.jpg" 如何将所有src值转换为png格式,如 <img src="http://example.com/cat.png" <img src="http://example.com/dog.png" <img s

dom由img属性组成,如

<img src="http://example.com/cat.jpg"
<img src="http://example.com/dog.jpg"
<img src="http://example.com/rat.jpg"

如何将所有src值转换为png格式,如

<img src="http://example.com/cat.png"
<img src="http://example.com/dog.png"
<img src="http://example.com/rat.png"
您的视图

向所有元素添加新类

<img class="old_image" src="http://example.com/cat.jpg">
<img class="old_image" src="http://example.com/dog.jpg">
<img class="old_image" src="http://example.com/rat.jpg">
你的观点

向所有元素添加新类

<img class="old_image" src="http://example.com/cat.jpg">
<img class="old_image" src="http://example.com/dog.jpg">
<img class="old_image" src="http://example.com/rat.jpg">

您可以在图像上循环并用.png替换.jpg

$(document).ready(function(){
  $("img").each(function(){
   var src=$(this).attr("src").replace(".jpg",".png");
  $(this).prop("src",src);
 });
});

您可以在图像上循环并用.png替换.jpg

$(document).ready(function(){
  $("img").each(function(){
   var src=$(this).attr("src").replace(".jpg",".png");
  $(this).prop("src",src);
 });
});