jQuery .trigger('blur') 在输入集合上?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8181508/
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
.trigger('blur') on collection of inputs?
提问by Dejan.S
im trying to trigger('blur');
on a collection of inputs but i does not seem to get this right.
我试图trigger('blur');
收集输入,但我似乎没有做对。
example is avaible here http://jsfiddle.net/VUUme/1/
示例在这里可用http://jsfiddle.net/VUUme/1/
im getting the collection and i got the blur method done but im not sure about the trigger part tho.
我得到了收藏,我完成了模糊方法,但我不确定触发部分。
var $inputs = $('#form').find('input');
alert('load');
$inputs.each(function(){
$(this).trigger('blur');
});
//i tried this to but with no success
//$inputs.trigger('blur');
alert('after the blur');
$inputs.blur(function(){
var $this = $(this);
if ($this.val() == ''){
alert('it works');
}
});
回答by Silver Light
Put trigger()
afteryou define $inputs.blur()
:
把trigger()
后您定义$inputs.blur()
:
alert('after the blur');
$inputs.blur(function(){
var $this = $(this);
if ($this.val() == ''){
alert('it works');
}
});
$inputs.trigger('blur');
Updated fiddle: http://jsfiddle.net/VUUme/3/
更新小提琴:http: //jsfiddle.net/VUUme/3/