【问题标题】:jquery validation required需要 jQuery 验证
【发布时间】:2009-11-01 13:10:16
【问题描述】:

我试过了,但它似乎不起作用,,,任何想法为什么不呢?

我这样称呼验证: $("#aspnetForm").validate().form();

无论“其他”是否选中,“详细信息”字段都是必需的......

我的例子来自http://jquery.bassistance.de/api-browser/plugins.html#jQueryvalidatormethodsrequiredStringElementBooleanStringFunction

10 倍!!

【问题讨论】:

  • 您应该提供更多信息。你有什么错误等等。“这不起作用”不允许这里的任何人帮助你。

标签: jquery validation


【解决方案1】:

确保包含所有必要的脚本:jquery.jsjquery.validate.jsjquery.metadata.js(如果您使用类元数据来定义验证规则)?这是一个示例:

<html>
<head>
    <title>Test</title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
    <script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery.validate/1.5.5/jquery.validate.min.js"></script>
    <script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/validate/lib/jquery.metadata.js"></script>
    <script type="text/javascript">
    $(function() {
        $('#aspnetForm').validate();

        $('a').click(function() {
            alert($('#aspnetForm').validate().form());
        return false;
        });
    });
    </script>
</head>
<body>

<form id="aspnetForm" action="#"> 
    <input name="other" type="radio" /> 
    <input name="details" type="text" class="{required:true}" />
    <input type="submit" value="OK" />
</form>

<a href="#">Validate</a>

</body>
</html>

【讨论】:

  • 我包含了所有必要的脚本:jquery.js、jquery.validate.js 和 jquery.metadata.js 我的代码: 但提交时仍需要输入,即使未选中复选框.....
【解决方案2】:

答案:

<input id="other" type="checkbox" />
  <br/>
  <input  class="{required:'#other:checked', messages:{required:'if you check it then fill it'}}"  />

代码有效! 无论如何,10X Darin Dimitrov ...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-28
    • 2014-09-29
    • 2013-04-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多