current position:Home>JQuery realizes picture switching

JQuery realizes picture switching

2022-04-29 13:33:12Dada front end

<div>
            <img class="imgclick" src="img/pic1.png" />
</div>

<script>
 $(".imgclick").toggle(function(){
  $(this).attr("src", "img/pic1.png");
  }, function() {
   $(this).attr("src", "img/pic2.png");
  }).attr("src", "img/pic1.png");
</script>

You can also use the background , Switch between two class. In this way, there is no need to bother the backend to modify js Picture path in .

utilize toggle Switch between different functions

copyright notice
author[Dada front end],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2022/119/202204291041434268.html

Random recommended