javascript - Javascript 的鼠标进出事件

标签 javascript jquery asp.net

初学者的问题..

我想在鼠标进入/离开父 div 时显示/隐藏内部 div。我首先尝试使用 onmouseoveronmouseout 事件,但问题是当鼠标悬停在 div 上时 onmouseover 继续触发,我希望它仅触发一次。

我找到了 JQuery可能对我有帮助的事件,但我不知道我可以把这段代码放在哪里,因为我的 div 存在于控件的模板中,并且 div 没有 onload 事件。

<script type="text/javascript" language="javascript">
    // Where should I call this !!!
    function Init(sender) {
        $(sender).bind("mouseenter", function () {
            $(sender.childNodes[1], this).show(500);
        }).bind("mouseleave", function () {
            $(sender.childNodes[1], this).hide(500);
        });
    }

</script>

任何帮助!

最佳答案

您可以使用 mouseentermouseleave事件。

您可以将您的代码放入并与这些事件绑定(bind)。

<script type="text/javascript" language="javascript">

    $(document).ready(function(){
        Init('.your_div_class');
    });

    function Init(sender) {
        $(sender).bind("mouseenter", function () {
            $(sender.childNodes[1], this).show(500);
        }).bind("mouseleave", function () {
            $(sender.childNodes[1], this).hide(500);
        });
    }

</script>

关于javascript - Javascript 的鼠标进出事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5337216/

相关文章:

asp.net - 更改用户登录名后认证错误

javascript - 使用 JavaScript 隐藏特定日期的面板

javascript - 隐藏 iframe 以防止内部服务器错误

javascript - React 删除推送历史记录中多余的问号

javascript - 鼠标悬停时暂停简单的推子脚本

javascript - 分页不起作用?? - jQuery 或 JavaScript

javascript - html中如何让页面从链接跳转?

asp.net - 符合 WCAG 2.0 的内容管理系统

javascript - 过渡 react 导航标题背景颜色

javascript - 如何动态获取td的宽度