简体   繁体   中英

Form validation with validate.js is not working

The validation is not working in the following code. I am using 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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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