与mouseenter关联的调用函数

Call function associated with mouseenter

本文关键字:调用 函数 关联 mouseenter      更新时间:2023-09-26

使用jQuery,我为元素添加了一个函数,如下所示:

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

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

$('#theId').mouseenter(theFunction);
function theFunction() {
    // ...
}
有了这个,我可以从脚本调用theFunction()。但是我想知道是否有一个函数来执行与#theId.mouseenter相关的函数。例如,可以通过执行$(elem).scroll();来运行与elem.scroll相关的函数。mouseenter会有类似的活动吗?

可以触发mouseenter:

$('#theId').trigger('mouseenter');
http://api.jquery.com/trigger/

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

使用 .trigger();

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