2013-08-20 171 views
-3

我有下面的jQuery代码来验证窗体。验证具有相同输入字段名称的表单?

function validateForm(){ 


     $("input.field1").each(function(){ 
     $(this).rules("add", { 
      required: true, 
      messages: { 
       required: "Required" 
      } 
     });    
    }); 



    $("input.fieldTwo").each(function(){ 
     $(this).rules("add", { 
      required: true, 
      maxlength: 12, 
      email: true 
      messages: { 
       required: "Enter email", 
       email: "Enter valid email", 
       maxlength: "Maximum 12 characters" 
      } 
     });    
    }); 



    $("input.field3").each(function(){ 
     $(this).rules("add", { 
      required: false, 
      maxlength: 12 
      messages: { 
       maxlength: "Maximum 12 characters" 
      } 
     });    
    }); 

    $("input.field4").each(function(){ 
     $(this).rules("add", { 
      required: false, 
      maxlength: 12 
      messages: { 
       maxlength: "Maximum 12 characters" 
      } 
     });    
    }); 

    $("input.field5").each(function(){ 
     $(this).rules("add", { 
      required: false, 
      maxlength: 12 
      messages: { 
       maxlength: "Maximum 12 characters" 
      } 
     });    
    }); 



     return $("#myForm").validate({ 
      onfocusout: function(element) { jQuery(element).valid(); } 
    }); 

    } 

但它总是给脚本错误说SyntaxError: missing } after property list

但我相信没有地方}是必需的。

我在这里失踪了吗?

谢谢!

+0

你错过了逗号...这真的是这个地方吗? :) – Splendiferous

+1

这个问题似乎是脱离主题,因为问题是一个类型错误 – iConnor

回答

0

您错过了几个逗号。查看代码,并在整个过程中复制。

$("input.fieldTwo").each(function(){ 
    $(this).rules("add", { 
     required: true, 
     maxlength: 12, 
     email: true //MISSING COMMA 
     messages: { 
      required: "Enter email", 
      email: "Enter valid email", 
      maxlength: "Maximum 12 characters" 
     } 
    });    
}); 

$("input.field3").each(function(){ 
    $(this).rules("add", { 
     required: false, 
     maxlength: 12 //MISSING COMMA 
     messages: { 
      maxlength: "Maximum 12 characters" 
     } 
    });    
}); 

$("input.field4").each(function(){ 
    $(this).rules("add", { 
     required: false, 
     maxlength: 12 //MISSING COMMA 
     messages: { 
      maxlength: "Maximum 12 characters" 
     } 
    });    
}); 
1

你在这里缺少一个逗号:

$("input.field3").each(function(){ 
     $(this).rules("add", { 
      required: false, 
      maxlength: 12, // added a comma here 
      messages: { 
       maxlength: "Maximum 12 characters" 
      } 
     });    
    }); 

你实际上已经错过了在每一个区域逗号maxlength财产之后。可能是复制和粘贴错误?

相关问题