jQuery复选框验证问题

时间:2011-11-20 14:23:05

标签: javascript jquery ajax validation

使用这个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">

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

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

更新 我有自定义错误处理程序。尝试了Alper的建议,收到此错误消息: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;
}

2 个答案:

答案 0 :(得分:1)

我不确定这会有所帮助,这篇文章涉及的是无线电按钮,但也许适用相同的规则 Validation of radio button group using jQuery validation plugin

答案 1 :(得分:0)

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

我乍一看,我认为你的代码中肯定会出现“js错误”。所以我建议您应该安装firebug并将其打开以关注“控制台”选项卡。然后你会看到senario的错误信息:“它没有验证,它会立即发布表格。”

相关问题