Change image onmouseover

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

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


    

        
相关标签:
8条回答
  • 2021-01-01 22:52

    Here is an example:

    HTML code:

    <img id="myImg" src="http://static.jquery.com/files/rocker/images/logo_jquery_215x53.gif"/>
    

    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.

    0 讨论(0)
  • 2021-01-01 22:54
    <a href="" onMouseOver="document.MyImage.src='http://icons.iconarchive.com/icons/uiconstock/round-edge-social/72/ask-icon.png';" onMouseOut="document.MyImage.src='http://icons.iconarchive.com/icons/uiconstock/round-edge-social/72/arto-icon.png';">
    <img src="http://icons.iconarchive.com/icons/uiconstock/round-edge-social/72/arto-icon.png" name="MyImage">
    

    Demo http://jsfiddle.net/W6zs5/

    0 讨论(0)
提交回复
热议问题