[英]How to execute a listener bound to an event and exclude the remaining listeners bound to different events from execution?
I have the following jQuery code: 我有以下jQuery代码:
$input.on('keyup', keyUpListener);
$input.on('input', inputListener);
// IE <= 8 fallback for input event.
$input[0].onpropertychange = function() {
if (window.event.propertyName === "value") {
inputListener(window.event);
}
};
$input
is a jQuery input[type='text']
. $input
是一个jQuery input[type='text']
。
Right now keyUpListener
and inputListener
are both executed when I type into the input
or when I copy and paste something ( onpropertychange
is not fired because it is an IE only event). 现在
keyUpListener
和inputListener
都是在我input
或者当我复制并粘贴某些内容时执行的( onpropertychange
未被触发,因为它是仅IE事件)。
But how can I tell JS to not fire inputListener
if keyUpListener
is executing and vice-versa? 但是,如果
keyUpListener
正在执行,我如何告诉JS不要触发inputListener
,反之亦然?
Attach the specific event to the textbox? 将特定事件附加到文本框?
$("#input").on('input', function () {
}
For instance the above - this way you can have multiple listeners not executing on the same input 例如上面 - 这样你就可以让多个监听器不在同一个输入上执行
EDIT 编辑
You are able to bind the paste function to the textbox also.. 您还可以将粘贴功能绑定到文本框..
$("#input").bind('paste', function() {
var pasted = true;
});
Thus you can then have the below IF statement: 因此,您可以使用以下IF语句:
if (pasted) {
$input.on('input', inputListener);
} else {
$input.on('keyup', keyUpListener);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.