2012-03-09 17 views
1

jquery fadeOut関数を使用して、検証応答メッセージ「このフィールドは必須」をフェードアウトするにはどうすればいいですか?Fiddle。私はちょうどメッセージがポップアップ(フェードインではない)し、そしておそらく3秒をかけてゆっくりとフェードアウトしたい。fadeOut検証メッセージJquery

これは検証プラグインを制御JSです:

$(document).ready(function() { 
     $('#commentForm').validate({ 
      submitHandler: function(form) { 
       $.ajax({ 
        type: 'POST', 
        url: 'process.php', 
        data: $(this).serialize(), 
        success: function(returnedData) { 
         $('#commentForm').append(returnedData); 
        } 
       });   
       return false; 
      }, 
      errorPlacement: function(error, element) { 
        error.insertAfter(element).position({ 
         my:'right top', 
         at:'right top', 
         of:element   
        }); 
       }   
     }); 
    }); 

はご入力いただき、ありがとうございます。

答えて

0

あなたがする必要があるのはerrorPlacement()error引数にコールフェードアウトです:

  errorPlacement: function(error, element) { 
       error.insertAfter(element).position({ 
        my:'right top', 
        at:'right top', 
        of:element   
       }); 
       error.fadeOut(3000); 
      } 

の作業例:http://jsfiddle.net/kmJ87/4/

+1

@maxedisonさん、ありがとうございます。 fadeOutが最初の検証応答でのみ機能する理由を理解できたら助かりますか? validatoinが2回目にトリガーされたとき、メッセージはfadeOutになりません。 –

+0

Fadeoutは機能しますが、もう一度submitをクリックすると、これらの関数が呼び出されます。 – Gowri

1

あなたが複数回実行タイミングフェードアウト効果をしたい場合は、必要にエラー要素が消えるとすぐに削除してください。

errorPlacement: function(error, element) { 
    error.insertAfter(element).position({ 
    my:'right top', 
     at:'right top', 
      of:element   
     }); 
     // here the magic happens, we remove the element, forcing the errorPlacement callback to be run every time 
     error.fadeOut(3000, function() { $(this).remove(); }); 
    } 
+0

ありがとうございます – Gowri

関連する問題