【问题标题】:How to detect jQuery event (ex. click mouseout) on or off?如何检测 jQuery 事件(例如 click mouseout)打开或关闭?
【发布时间】:2012-11-01 07:41:38
【问题描述】:

默认

$().mouseout(function(){…})

mouseout 事件在页面中开启

我可以用任何方式检测事件是否开启

我希望检测方法返回一个布尔值供我使用。

希望看到你的答案。

【问题讨论】:

    标签: jquery event-handling jquery-events jquery-on


    【解决方案1】:

    使用$._data,是的!

    是的,您可以通过以下方式进行检查:

    console.log($._data( $(element)[0], "events" ));
    

    示例

    ​$("#foo").on({
        click: function(){ alert("Hello") },
        mouseout: function(){ alert("World") }
    });​​​
    ​$._data( $("#foo")[0], "events" );
    

    输出

    在您的代码中:

    因此,您可以使用返回的对象并执行操作。

    myEvents = ​$._data( $("#foo")[0], "events" );
    // Check if the mouse event is set
    if (myEvents.mouseout.length > 1)
        // Do something
    

    【讨论】:

    • 您好,感谢您的帮助,我想问一下,在这种情况下,$("#foo")[0] 存在点击事件,对吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-04
    • 1970-01-01
    • 2014-12-09
    • 2019-01-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多