【问题标题】:Call function associated with mouseenter调用与 mouseenter 关联的函数
【发布时间】:2013-04-17 15:13:01
【问题描述】:

使用 jQuery,我向这样的元素添加了一个函数:

$('#theId').mouseenter(function(){
    // ...
});

现在,我想从脚本中调用与#theId.mouseenter 关联的函数。我知道这是可能的:

$('#theId').mouseenter(theFunction);
function theFunction() {
    // ...
}

有了这个,我可以从脚本中调用theFunction()。但我想知道是否有一个函数可以执行与#theId.mouseenter 关联的函数。例如,可以通过执行$(elem).scroll(); 来运行与elem.scroll 关联的函数。 mouseenter 事件有类似的东西吗?

【问题讨论】:

  • 在询问之前您至少尝试过$(elem).mouseenter(); 吗??
  • @adeneo 实际上,我做到了,它没有工作(或者我的代码有问题,我现在正在检查......)

标签: javascript jquery jquery-events mouseenter


【解决方案1】:

你可以触发 mouseenter :

$('#theId').trigger('mouseenter');

http://api.jquery.com/trigger/

【讨论】:

    【解决方案2】:

    您实际上根本不需要触发器 - 只需 $('#theId').mouseenter();

    【讨论】:

      【解决方案3】:

      使用.trigger();

      $('#theId').trigger("mouseenter");
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-03-06
        • 2023-03-23
        • 1970-01-01
        • 2011-02-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多