在验证js中,SyntaxError:缺少形式参数

时间:2016-06-23 11:12:44

标签: jquery jquery-validate

我在jQuery选择器中有语法错误。我使用ajax添加多行并尝试使用validation.js验证它的客户端..

在控制台中,我看到错误

  

“SyntaxError:缺少形式参数”。

$(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();
  }

});

});

使用此代码我验证文本框和下拉列表

我添加了console screen enter image description here

3 个答案:

答案 0 :(得分:1)

你遗失的地方“)”或“}”。尝试找出其他你可以保存

答案 1 :(得分:0)

在Sparky的评论之后修改了我的帖子。我应该在发布之前提到jquery验证选项。

请参考他的回答,我已相应地修改了我的代码:

table tbody tr td

答案 2 :(得分:0)

您尝试使用.validate()方法:

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

您无法在.each()内放置.validate功能!您只能使用由angulartics组成的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:options that are provided by the developer

相关问题