jQuery 我可以防止发生模糊事件吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13509484/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can i prevent blur event from happening?
提问by Tomer
I have a simple example where i have an input
field and i put a blur
and change
event on it:
我有一个简单的例子,我有一个input
字段,我在上面放了一个blur
和change
事件:
HTML
HTML
<input name="test" value=""/>
JS
JS
$('input').change(function(e){
alert('change');
});
$('input').blur(function(e){
alert('blur');
});
Is it possible to prevent the blur
event from happening if the change
event was triggered?
blur
如果change
事件被触发,是否可以阻止事件发生?
One way would be to define a boolean that changes when the change event was triggered, but I don't like it, is there a better way?
一种方法是定义一个在触发更改事件时更改的布尔值,但我不喜欢它,有没有更好的方法?
Hereis an example you can play with.
这是您可以使用的示例。
回答by Akhil
回答by Pragnesh Chauhan
回答by Raab
you can use
您可以使用
this.unbind('blur');
on the onchange call
this.unbind('blur');
在通话中
回答by s.Daniel
If I understand you correctly the answer is to use event.preventDefault();
See http://jsbin.com/welcome/52201/editfor a demo.
如果我理解正确,答案是使用event.preventDefault();
See http://jsbin.com/welcome/52201/edit进行演示。