2010-10-22 5 views
1

Je ne veux que paramétrer le code pour en alerter un lorsque je ne suis plus en «focus» mais l'alerte continue à s'accumuler si je clique sur le champ de saisie et sur 'focus' plus d'un?jquery: focus et flou sur le champ de saisie du mot de passe

http://nano-visions.net/dump2/focus/

$(document).ready(function(){ 

    $(function() { 
    $('#test-form-1 *[title]').inputHint(); 

    }); 

    $(".input-password").each(function(){ 

     if($(this).length > 0) 
     { 
      /* create the password input next to the current input and hide the password input */ 
      var val_name = $(this).attr('name'); 
      $(this).after("<input name='"+val_name+"' type='password' value='' />"); 
      $(this).next().hide(); 

      /* on focus */ 
      $(this).focus(function() { 

       /* hide the input and display the next input and put focus on it */ 
       $(this).hide(); 
       $(this).next().show().focus(); 

       //alert($(this).parent().html()); 
       //var keep_html = $(this).parent().html() 

       /* on blur */ 
       $(this).next().blur(function(){ 

        /* if the password input is empty */ 
        if($(this).val() == '') 
        { 
         $(this).hide(); 
         $(this).prev().show(); 
         $('form *[title]').inputHint(); 
        } 
        alert($(this).parent().html()); 

       }) 
      }); 


     } 
    }); 

}); 

le code html

<form method="post" id="test-form-1"> 
    <div><input value="" class="hint input-password" title="Password" name="password" type="text"></div> 
</form> 

Ai-je écrire quelque chose de mal? comment puis-je le réparer?

Merci!

Répondre

1

Parce que chaque fois qu'il est sur le point de focalisation, vous liez l'élément suivant à l'événement de flou encore et encore.

Au lieu de:

$(this).focus(function() { 
    // code 
    $(this).next().blur(function(){ 
    //code 
    }) 
}); 

Essayez cette

$(this).focus(function() { 
    // code 
}).next().blur(function(){ 
    //code 
}); 

J'espère que cela aide!

+0

merci! oui ça fonctionne maintenant parfaitement! Merci! – laukok

Questions connexes