本文介绍了按Enter键进入文本框后,防止模糊和键盘事件触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
按我希望只触发 keyup
事件但是 blur
先被解雇。使用
After pressing I would like that only the keyup
event be fired but blur
is fired first. How to cancel blur
when keyup
is fired with ?
请不要建议将 blur
和 keyup
绑定到一个 live()
方法。
Please don't suggest to bind both blur
and keyup
into a single live()
method.
$(".textbox").on("blur",function () {
alert("blur Event fired");
});
$(".textbox").on("keyup",function (event) {
if(event.keyCode == 13){ // Detect Enter
alert("KeyUp fired after pressing Enter");
}
});
推荐答案
我无法改变 class
属性所以我最终得到了,
I Couldn't alter class
attribute so i'd ended up with,
$(".textbox").on("blur",function () {
if($(this).attr('flag')!='1')
alert("blur Event fired");
});
$(".textbox").on("keyup",function (event) {
$(this).attr('flag','1');
if(event.keyCode == 13){ // Detect Enter
alert("KeyUp fired after pressing Enter");
}
$(this).attr('flag','0');
});
这篇关于按Enter键进入文本框后,防止模糊和键盘事件触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!