使用jquery-validate.js进行表单验证 [英] form validation using jquery-validate.js

查看:96
本文介绍了使用jquery-validate.js进行表单验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有问题,我没有做错什么,因为我遵循了几个示例,但它们都没有起作用,我没有得到任何错误,任何信号,什么也没有,也许有人可以帮助我

I have a problem and I don't what am i doing wrong since I follow several examples and none of them worked, I dont get any error, any signal, nothing, maybe someone can help me

这是我的代码 HTML:

Here's my code HTML:

 <form id="contact" method="post" action="#">
                <fieldset>
                    <label for="name">NAME</label>
                    <input type="text" class="required input-xlarge" id="name-contact" name="name-contact" value="" placeholder="" minlength="2">

jQuery:

   $( "#contact" ).validate({
        rules: {
               "name-contact":{
                   required: true
               } 
       },
       messages: {
            "name-contact": {
                required: "Please, enter a name"
            }
       }

   });

这是我第二次尝试使用此插件,因为它看起来非常简单,对我没有帮助 预先感谢

this is the second time i tried to use this plug in because it looks very easy, it hasnt for me Thanks in advance

推荐答案

您发布的代码运行正常,如您所见:

http://jsfiddle.net/NP8sS/

http://jsfiddle.net/NP8sS/

一些注意事项,但是只有第一项可以完全打破事情:

Some notes, however only the first item could totally break things:

1)也许您忘记了包括jQuery和/或jQuery Validate插件.在框架"和外部资源"下查看jsFiddle的左侧面板.您遇到任何JavaScript错误吗?

1) Perhaps you forgot to include jQuery and/or jQuery Validate plugin. Look at the left panel of the jsFiddle under "Frameworks" and "External Resources". Are you getting any JavaScript errors?

您应该按此顺序的两行,其中src包含指向放置这些文件的位置的正确URL:

You should have two lines, in this order, where the src contains the correct URL to the location where you've placed those files:

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


2)您已经在两个地方指定了规则.在.validate()内具有required规则,在name-contact元素内具有minlength规则.也许更加一致,而是将它们放在一起:


2) You've specified rules in two places. You have the required rule inside .validate() and the minlength rule inside the name-contact element. Maybe be more consistent and put them together instead:

http://jsfiddle.net/NP8sS/1/

rules: {
    "name-contact": {
        required: true,
        minlength: 2
     }
},


3) <label>中的for属性包含无效的name.应该是:


3) Your for attribute in your <label> contains an invalid name. Should be:

<label for="name-contact">NAME</label>


4)您没有关闭<form>.您需要在最后放置</form>标记.


4) You did not close your <form>. You need to put a </form> tag at the end.

这篇关于使用jquery-validate.js进行表单验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆