简体   繁体   English

使用validate.js进行表单验证不起作用

[英]Form validation with validate.js is not working

The validation is not working in the following code. 验证在以下代码中不起作用。 I am using validate.js. 我正在使用validate.js。 Can please anybody point out the problem ? 可以请任何人指出问题吗?

<form id="tf">
    <input type="text" id="q" name="q" />
    <input type="submit" value="Submit" />
</form>

<script type="text/javascript">
    $(document).ready(function () {
        $("#tf").validate({
            rules: {
                q: {
                    required: true
                }
            },
            messages: {
                q: {
                    required: "Done"
                }
            }
        });
    });
</script>

我认为您需要添加一个类而不是一个ID来使验证工作。

<input type="text" id="q" class="q" name="q" />

Have you tried adding 您是否尝试过添加

class="required"

to the inputs? 输入?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM