.net - jquery mouseenter 鼠标离开

标签 .net jquery

我无法让鼠标进入鼠标离开功能正常工作。我知道我可以使用 .hover 选项,我想让 mouseenter/mouseleave 正常工作,然后再进行操作。

我看到的是,我打开了 chrome,正在检查 img,它说 src 文件正在更改,但我没有看到明显的变化。有人可以帮忙吗

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>

    <script src="jquery-1.4.3.min.js" type="text/javascript"></script>


</head>
<body>

            <img id="menuHome" src="m_home.gif" />
                <script type="text/javascript">

                    $(document).ready(function() {
                        $("#menuHome").mouseenter(function() {
                            $(this).attr({ src: 'm_home_roll.gif' });
                        });
                        $("#menuHome").mouseleave(function() {
                            $(this).attr({ src: 'm_home.gif' });
                        });
                    });
    </script>

</body>
</html>

最佳答案

我认为 Chrome 也有类似的问题,我似乎记得使用 mouseovermouseout 来代替。所以像这样:

$(document.ready(function() {
    $('#menuHome')
        .mouseover(function() {
            $(this).attr({src: 'm_home_roll.gif'});
        })
        .mouseout(function() {
            $(this).attr({src: 'm_home.gif'});
        });
});

也无需选择该元素两次(因此只有一个 $('#menuHome') 行)。

关于.net - jquery mouseenter 鼠标离开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4158957/

相关文章:

c# - 来自运行时数据层的 C# 中的动态 odata 服务

.net-框架和.net常规

.net - MDI Child .Show() 方法在框架中引发 NullReferenceException

c# - 在 foreach 循环外声明变量

javascript - 从另一个 DropDownList 填充 DropDownList

javascript - 从 .toggle 访问 $(this)

javascript - jQuery 错误 : . ..easing... 不是函数

c# - 对文件夹名称数组进行排序,如 Windows 资源管理器(按数字和字母顺序)- VB.NET

javascript - 页面刷新后div有不同的宽度

javascript - 未捕获类型错误 :undefined is not a function while using slide left infullpage. js