Change image onmouseover

后端 未结 8 2053
野趣味
野趣味 2021-01-01 21:47

What\'s the correct way to change an image on mouseover and back on mouseout (with/without jQuery)?


    

        
8条回答
  •  猫巷女王i
    2021-01-01 22:52

    Here is an example:

    HTML code:

    
    

    JavaScript code:

    $(document).ready(function() {
        $( "#myImg" ).mouseover(function(){
            $(this).attr("src", "http://www.jqueryui.com/images/logo.gif");
        });
    
        $( "#myImg" ).mouseout(function(){
            $(this).attr("src", "http://static.jquery.com/files/rocker/images/logo_jquery_215x53.gif");
        });
    });
    

    Edit: Sorry, your code was a bit strange. Now I understood what you were doing. ;) The hover method is better, of course.

提交回复
热议问题