0

私はjQueryとPHPを利用するbitrepository.comの素晴らしいAJAXフォームを使用しています:http://www.bitrepository.com/a-simple-ajax-contact-form-with-php-validation.html

クリックしてフェードインした後に表示されるエラーと検証のDIVが欲しいのですが。

次のjQueryコードを追加しましたが、役に立ちませんでした(クリック/変更機能でも試してみました)。

$(document).ready(function(){
    if ($('.notification_error').length > 0) {
        $('.notification_error').fadeTo("slow", 1.0);
    }
});

どんな助けでも素晴らしいでしょう...

4

2 に答える 2

2

コードが参照したものとまったく同じように見える場合、ajax-completeコールバックを次のように変更できます。

$("#note").ajaxComplete(function(event, request, settings){  

   if(msg == 'OK') // Message Sent? Show the 'Thank You' message and hide the form
   {
      result = '<div class="notification_ok">Your message has been sent. Thank you!</div>';
      $("#fields").hide();
   }
   else
   {
      result = msg;
   }
   /* Hide the element, alter the content, and then fade it in */
   $(this).hide().html(result).fadeIn("slow"); 
});

これにより、エラーメッセージと成功メッセージの両方がフェードインします。

アップデート:

初めて要素をフェードさせるには、最後の行を次のように置き換えることができます。

if ($(".notification_error, .notification_ok", this).length === 0) {
    $(this).hide().html(result).fadeIn("slow"); 
} else {
    $(this).html(result);
}

私たちが行うことは、クラスnotification_errorまたはのいずれかを持つen要素があるかどうかをチェックすることですnotification_ok。そうでない場合(初めて)はフェードインし、そうでない場合はコンテンツを更新します。

于 2012-07-31T18:34:29.423 に答える
1

次のことを試してください。

$("#clicked_input_id").click(function(){
    $('.notification_error').fadeTo("slow", 1.0);
});
于 2012-07-31T18:30:41.633 に答える