【问题标题】:jQuery Validation plugin - unnecessary validationjQuery Validation 插件 - 不必要的验证
【发布时间】:2014-05-04 09:16:15
【问题描述】:

我正在使用 jQuery 验证插件 (v1.12.0) 来验证 HTML 表单。 在表单上使用默认的validate() 方法时(没有任何规则),它会检查文本输入的最小值/最大值,并且由于输入值是字符串,因此返回以下消息:请输入更大的值大于或等于 0。

知道是什么导致了这种行为,以及如何阻止插件自动验证这些输入,使其仅根据rules 对象中指定的内容进行验证?

以下是重现问题的代码:

<html>
<head>
        <title>Validation Test Page</title>

</head>
<body>

<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="jquery.validate.min.js"></script>

<div id="main_div">
        <div id="content_div">
                <h2 id="title">Validation Test Page</h2>
                <form id="new_customer_form" class="validate" action="generate.php" method="post" enctype="multipart/form-data">

                        Customer Name: <input id="inp_cust_name" class="tooltip" type="text"
                                name="inp_cust_name">

                        Title: <input id="inp_title" class="tooltip" type="text" name="inp_title"><br>

                        Custom text: <textarea id="inp_text" class="tooltip" name="inp_text" placeholder="Enter text here"></textarea><br>

                        Customer logo: <input id="inp_file" class="tooltip" type="file" name="inp_file"><br>

                        <div id="action_div_create">
                                <input id="inp_submit" type="submit" name="inp_submit" value="Submit">
                                <a href="./"><button type="button">Cancel</button></a>
                        </div>

                </form>
                <script>
                        $(document).ready(function() {
                                $("#new_customer_form").validate({
                                        rules: {
                                                inp_cust_name : {
                                                        required: true
                                                }
                                        }

                                });
                        });


                </script>

        </div>
</div>

</body>
</html>

【问题讨论】:

  • 如果解决方案是更新 jQuery,请将其作为答案发布在下面,而不是编辑问题。谢谢。

标签: jquery jquery-validate


【解决方案1】:

这是在使用 jQuery 1.3.2 时发生的。当更改为 jQuery 1.11.1 时,问题消失了。 这可能是错误或其他问题 - 如果您有任何有用的信息,请随时添加。

【讨论】:

  • 这不是一个错误,因为这只是一个插件与非常旧版本的 jQuery 的严重不兼容。 jQuery 1.3.2 太老了(大约在 2009 年),这类似于说 Facebook.com 在 Internet Explorer 5.5 版中看起来很奇怪。它只是从来没有打算发生。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-10-04
  • 2018-07-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-19
相关资源
最近更新 更多