【问题标题】:jQuery checkbox validation issuejQuery复选框验证问题
【发布时间】:2011-11-20 14:23:05
【问题描述】:

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

【问题讨论】:

  • 在 jQuery 调用中尝试使用 accomationtype 而不是 accomationtype[]?
  • 报错,该字段不存在
  • 具有讽刺意味的是,您链接的验证器的不那么全面的演示页面没有显示如何验证复选框或复选框组。如果您打算使用该验证器,我会联系作者。
  • 试过了,他没有回答。使用这个验证器,因为使用非常简单。您可以创建自定义错误处理程序。
  • 检查这个小提琴:jsfiddle.net/Lz5gg/1 它按预期工作。

标签: javascript jquery ajax validation


【解决方案1】:

我不确定这是否会有所帮助,这篇文章正在处理单选按钮,但可能适用相同的规则 Validation of radio button group using jQuery validation plugin

【讨论】:

    【解决方案2】:

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

    乍一看,我认为您的代码中一定发生了“js错误”。所以我建议你应该安装 firebug 并让它打开聚焦“控制台”选项卡。然后您将看到 senario 的错误消息:“它没有验证并立即发布表单。”

    【讨论】:

    • 嗨。请给我你的 Skype 联系方式,以便我可以和你聊天
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-10
    • 2017-09-05
    相关资源
    最近更新 更多