0

我是 jquery 的新手。我在谷歌搜索,我得到了验证插件。但它不起作用。我在标题部分附加了 jquery.validate.js。

我的代码看起来像......

  <form action="" method="" id="contact">
            <div class="form-group"">
                <label> Your Name </label>
                <input type="text" class="form-control" placeholder="Enter Your Name" id="firstname" required="" minlength="5"/>
            </div>

            <div class="form-group">
                <label> Your E-mail </label>
                <input type="email" class="form-control" placeholder="Enter Your Email" id="email"/>
            </div>
  <button type="submit" class="btn btn-primary btn-lg"> Send</button>
 </form>

  <script type="text/javascript"> 
    $('#contact').validate({
     success: function(label){
    label.addClass("has-success").text("ok");
    }
  });
</script>

但它并没有验证我的领域......谁能说如何使用它?我知道我在这里做错了,但我是新手,所以...

4

3 回答 3

1

The submit button is essencial since it fires the validate function:

$("#myform").validate({
  submitHandler: function(form) { // this line is important
    form.submit(); // with this line the validate function gets fired
  }
 });

perhaps you should also try following:

– make sure your jquery library is correctly embedded in your document

– make sure your validation.js is in the correct folder

于 2013-10-23T10:31:34.900 回答
1

尝试使用文档就绪指令:

$(function(){
   $('#contact').validate();
});

它有效:http: //jsfiddle.net/RQMaV/15/

于 2013-10-23T10:24:51.163 回答
1

您是否在项目目录中包含 jquery-plugin validation.js 文件?如果没有,那么您需要包含http://www.websitecodetutorials.com/code/jquery-plugins/validation.js

于 2013-10-23T10:29:01.900 回答