Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jquery定义自己的事件?_Jquery_Events_Settimeout_Blur - Fatal编程技术网

jquery定义自己的事件?

jquery定义自己的事件?,jquery,events,settimeout,blur,Jquery,Events,Settimeout,Blur,是否可以在这些情况下触发的输入上定义事件 a) is called on blur of input IF the remaining conditions are true b) if the autocomplete list is visible halt the event until it is closed c) if the autocomplete list closes without an item being selected then the event is fired

是否可以在这些情况下触发的输入上定义事件

a) is called on blur of input IF the remaining conditions are true b) if the autocomplete list is visible halt the event until it is closed c) if the autocomplete list closes without an item being selected then the event is fired d) if the autocomplete list closes with an item being selected the event is not fired e) if the reason the blur was caused was because an item in the autocomplete was clicked the event is not fired a) 如果其余条件为真,则在输入模糊时调用 b) 如果“自动完成”列表可见,则暂停事件,直到其关闭 c) 如果自动完成列表在未选择项目的情况下关闭,则会触发事件 d) 如果“自动完成”列表在选定项目后关闭,则不会触发事件 e) 如果造成模糊的原因是单击了自动完成中的某个项目,则不会触发该事件 正如你所看到的,这件事有相当大的影响。 我不能在模糊事件中使用正常的setTimeout,因为用户可能坐在自动完成列表上,而没有实际选择任何内容

也许我可以在autocomplete open上设置一个变量,以便我们知道它仍然处于打开状态。
如果计时器过期且自动完成功能仍然打开,我们可以重置计时器。
然后在关闭时,我们可以取消设置变量。
或者选择一个项目,我们可以取消定时器

您认为如何?

您可以使用引发自定义事件并为其附加侦听器。代码将类似于:

$(yourinput).blur(function(){
    if(....your condition....)
        $.fling('publish','YourEventName',your data in json);
}
要附加侦听器,请执行以下操作:

 $.fling('subscribe','YourEventName', function(){
 });

可以使用该函数触发您自己的事件。这意味着您可以在代码中的不同点调用事件,因此不必编写复杂的构造

只需这样调用:
$('.yourClass').trigger('myEvent')

可以通过
.bind()
链接到此事件,即
$('.yourClass').bind('myEvent',function(){
});