切换图像上的src属性

tim*_*mkl 0 javascript jquery

有没有办法在单击锚点时在两个值之间切换图像的src属性?

像这样:

$('a#some-anchor').click(function() {
// code here that toggles between two image src's e.g. "images/some-image1.jpg" and "images/some-image2.jpg"
});
Run Code Online (Sandbox Code Playgroud)

ben*_*e89 8

$("img").bind("click", function() {
  var src = ($(this).attr("src") === "img1_on.jpg")
                ? "img2_on.jpg" 
                : "img1_on.jpg";
  $(this).attr("src", src);
});
Run Code Online (Sandbox Code Playgroud)

取自这里:

使用jQuery更改图像源