2011-11-18 5 views
7

Im essayant de trigger('blur'); sur une collection d'entrées mais je ne semble pas obtenir ce droit..trigger ('flou') sur la collecte des entrées?

exemple est avaible ici http://jsfiddle.net/VUUme/1/

im la collecte et obtenir i a la méthode de flou fait, mais je ne suis pas sûr de la partie déclencheur 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'); 
    } 
}); 

Répondre

16

Mettez trigger()après vous définissez $inputs.blur():

alert('after the blur'); 

$inputs.blur(function(){ 
    var $this = $(this); 
    if ($this.val() == ''){ 
    alert('it works'); 
    } 
}); 

$inputs.trigger('blur'); 

violon Mise à jour: http://jsfiddle.net/VUUme/3/

+0

ofcause Comment pourrais-je manquer. Merci –

Questions connexes