2016-06-23 22 views
1

私はjQueryのselector.Iに構文エラーがあり、AJAXを使用してvalidation.jsを使用してクライアント側にそれを検証しようとしている複数の行を追加しています。..コンソールで:行方不明の仮パラメータ

、私はエラーが表示しますこのコードを使用

"SyntaxError: missing formal parameter".

$(document).ready(function(){ 
$("#bookingadd").validate({ 

    $('input[type=text]').each(function(){ 

       $(this).rules("add", "required"); 
      }); 

    $('select').each(function(){ 
       $(this).rules("add", "selectsubservices"); // value is not 0 
      }); 

    submitHandler: function(){ 

    setTimeout(function(){}, 2000); 

    jQuery("#bookingadd").submit(); 
    } 

}); 

}); 

Iは、テキストボックス、ドロップダウン

私はconsole screen enter image description hereを追加検証します

答えて

0

はあなたの試み! options that are provided by the developerで構成されたkey:valueのペアのコンマ区切りのリストのみを置くことができます。

また、.rules()メソッドはスタンドアロンのjQuery Validateメソッドであり、別のjQuery Validateメソッドの内部には入れません。

あなたの構造がより次のようになります...

$(document).ready(function() { 

    $("#bookingadd").validate({ 
     submitHandler: function (form) { // <- you missed the 'form' argument 
      .... 
      form.submit(); // <- you can use the 'form' argument here 
      /* you don't need the timer here, 
      so if you remove it, then there is 
      no point in having the 'submitHandler' at all, 
      as 'form.submit()' is already the default. 
      Just remove the 'submitHandler' entirely. */ 
     } 
    }); // end .validate() 

    $('input[type=text]').each(function() { 
     $(this).rules("add", "required"); 
    }); 

    $('select').each(function() { 
     $(this).rules("add", "selectsubservices"); // value is not 0 
    }); 

}); 

DEMO:jsfiddle.net/r416reg6/

+0

ありがとう –

1

どこかに ")"または "}"がありません。他を見つけることを試みなさい

+0

彼はどんなかっこまたは角カッコが欠落していません。彼は '.valid()'メソッドの中に '.rules()'メソッドを間違って貼り付けています。後者は、開発者が提供するオプションからなる 'key:value'のペアを取得することになっています。 – Sparky

0

Sparkyの発言の後で私のポストを変更しました。投稿する前にjquery検証オプションを参照しておくべきです。

彼の答えを参照してください、私はそれに応じて自分のコードを変更した:

$("#bookingadd").validate({ 
    $('input[type=text]').each(function(){ 
     $(this).rules("add", "required"); 
     .... 

あなたは.validateの内側.each()機能を置くことはできません。.validate()方法と

$(document).ready(function(){ 
     $("#bookingadd").validate({ 
      submitHandler: function (form){ 
      form.submit(); 
      } 
     }); 
     $.each($('input[type=text]'),function(){ 
      $(this).rules("add", "required"); 
     }); 
     $.each($('select'),function(){ 
      $(this).rules("add", "selectsubservices"); // value is not 0 
     }); 
}); 
+0

'.validate()'メソッドの中に '.rules()'メソッドを間違って貼り付けています。後者は '' key:value'のペアを[開発者が提供するオプション] https://jqueryvalidation.org/validate)。 – Sparky

関連する問題