简体   繁体   中英

Image change on hover

Hi, I have a HTML image that is setup like this:

<input id="img" type="image" src="">

How can I change src on hover?

.

Try this:

<script type="text/javascript">
$(document).ready(function(){
   $("#img").hover(function(){
      $(this).attr("src","img1.jpg");
   },function(){
      $(this).attr("src","img2.jpg");
   });
});
</script>
<input id="img" type="image" src="">

Expecting an item to be hovered on i suggest this:

   $('.item').mouseover(function (e) {
    var id = $(this).val();
    $("#img").attr("src",id);
  });

use jQuery for this tag

<input id="img1" type="image" src="">

$("#img1").hover(function() {
  $(this).addClass("blue");
}, function() {
  $(this).removeClass("blue");
});

in css class you can write src for this input image tag.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM