简体   繁体   English

如何在具有焦点的jQuery中添加多个事件委托

[英]How to add multiple event delegation in jquery with focusout

I am trying to execute two events with one "on" function. 我正在尝试使用一个“ on”功能执行两个事件。 I have this code: 我有以下代码:

<input type="text" id="lesson" />

$('#lesson').on("focusout keyup",function(e){
    var $change_education = $(this);
    if(e.which === 188){
       var current_value = $(this).val();
       add_edit_tags(current_value, $change_education);
    }
});

The keyup event is working but the focusout is not. keyup事件正在工作,但焦点不在。 I can't see anything from the web how to solve this. 我从网上看不到任何解决方法。

Thanks 谢谢

The problem seems to be that you are checking for e.which === 188 which will not be set if it is a focusout event, change the condition as below and check 问题似乎是您正在检查e.which === 188如果它是focusout事件则不会设置,请按如下所示更改条件并检查

$('#lesson').on("focusout keyup",function(e){
    var $change_education = $(this);
    if(e.type == 'focusout' || e.which === 188){
       var current_value = $change_education.val();
       add_edit_tags(current_value, $change_education);
    }
});

Demo: Fiddle 演示: 小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM