0

ファンシーボックスポップアップを起動したい

フォームが検証されたら、fancybox ポップアップを表示するだけで済みます (JQUERY Validate を使用)

フォームが正しく入力されていない場合にのみ、fancybox ポップアップがポップアップするようです!

http://gloss-hair.com/old/owl/OWLFORM.html

フォームが検証された後にのみ popup fancybox 関数をロードする方法がわかりません。

  <script type="text/javascript">
$().ready(function() {
    // validate the competition form when it is submitted
    $("#ie9_competition").validate({
        errorPlacement: function (error, element) {   
            if ( element.is(":checkbox") ) {
                error.appendTo( element.closest('div') );
               }
            else { 
                error.insertAfter(element.parent().find("label"));           
                 }
            },
        rules: {            
            sEmail: {
                required: true,
                email: true
            },

        }
    });         
}); 

<script type="text/javascript">
    $(document).ready(function() {
        $(".fancybox4").fancybox({
            'hideOnContentClick': true
        });
    });
</script>
4

2 に答える 2

2

jQuery Validationプラグインを使用すると、フォームが有効な場合に実行されるsubmitHandlerを定義できます。

submitHandler: function(form){
  form.submit(); // submit the form
  // code to show your fancybox here
}

validate()コードは次のようになります。

$("#ie9_competition").validate({
 errorPlacement: function (error, element) {   
  if ( element.is(":checkbox") ) {
   error.appendTo( element.closest('div') );
  } else { 
   error.insertAfter(element.parent().find("label"));           
  }
 },
 rules: {            
  sEmail: {
   required: true,
   email: true
  }
 },
 submitHandler: function(form){
  form.submit(); // submit the form
  // code to show your fancybox here
 }
});

ここでvalidate()メソッドで利用可能なすべてのオプションを確認できます:http://docs.jquery.com/Plugins/Validation/validate#toptions

于 2012-04-09T16:55:44.597 に答える
1

このようにしてみてください

$().ready(function() {
        // validate the competition form when it is submitted
        $("#ie9_competition").validate({
            errorPlacement: function (error, element) {   
                if ( element.is(":checkbox") ) {
                    error.appendTo( element.closest('div') );
                   }
                else { 
                    error.insertAfter(element.parent().find("label"));           
                     }
                },
            rules: {            
                sEmail: {
                    required: true,
                    email: true
                },

            },          
            submitHandler: function(form){

                jQuery('.fancybox4').trigger('click');

            }
        });         
    }); 

onsubmit次に、form タグからイベントを削除します。したがって、フォームタグは次のようになります

<form id="ie9_competition" method="post">
于 2012-04-10T03:25:16.143 に答える