2011-11-20 90 views
0

使用此jQuery验证插件。jQuery复选框验证问题

http://www.benjaminkeen.com/software/rsv/jquery/index.php

我想验证与JS复选框组,但是当我使用的语句:

rules.push("required,accomodationtype[],Please check all that apply"); 

rules.push("required,accomodationtype\[\],Please check all that apply"); 

这类复选框组:

<INPUT type="checkbox" name="accomodationtype[]" id="accomodationtype_0" value="hotel1">Hotel1<BR> 
<INPUT type="checkbox" name="accomodationtype[]" id="accomodationtype_1" value="hotel2">Hotel2<BR> 
<INPUT type="checkbox" name="accomodationtype[]" id="accomodationtype_2" value="hotel3">Hotel3<BR> 
<INPUT type="checkbox" name="accomodationtype[]" id="accomodationtype_5" value="other"> Other (please specify)<BR> 
<INPUT type="text" name="accomodationtypeother" id="accomodationtypeother"> 

它不验证,它立即发布表单。我不确定我是否做错了什么。

有人可以帮助这种情况吗?

UPDATE 我有自定义错误处理程序。试图阿尔珀的建议收到此错误信息:errorInfo[i][0].focus is not a function

function errorHandler3(f, errorInfo) 
{ 
    for (var i=0; i<errorInfo.length; i++) 
    { 
     // errorInfo[i][0] contains the form field node that just failed the validation, e.g. 
     errorInfo[i][0].focus(); 
     // errorInfo[i][1] contains the error string to display for this failed field, e.g. 
     $.notifyBar({ 
      cls: "error", 
      html: errorInfo[i][1] 
     }); 

    } 


    if (errorInfo.length == 0) tcrform_submit(); 
    return false; 
} 
+0

尝试在jQuery调用中使用accomationtype而不是accomationtype []? – Cyclonecode

+0

它给出了错误,这个字段不存在 –

+0

具有讽刺意味的是,你链接的验证器的不太全面的演示页面没有显示如何验证复选框或复选框组。如果您使用该验证器,我会联系作者。 –

回答

0

单选按钮有没有足够的信息,这问题。
请附上整个代码(js,html),以便我们可以为您进行调试。

对于我的第一眼,我认为必须在您的代码中出现“js错误”。所以我建议你应该安装萤火虫,并打开聚焦“控制台”选项卡。那么你会看到senario的错误信息:“它没有验证,它立即发布表单。”

+0

嗨。请给我你的Skype联系人,以便我可以与你聊天 –