简体   繁体   English

使用Jquery验证来验证表单

[英]Validate form with Jquery validation

I want to validate my form, but I had this error : 我想验证我的表格,但是出现了这个错误:

Uncaught TypeError: $(...).validate is not a function

I included the js files validation jquery-validate.min.js and jquery-validate.js.Thanks 我包括了js文件验证jquery-validate.min.js和jquery-validate.js。

index.html index.html

<form id="form1">
<label for="phone">First Name</label>
<input type="text" name="name" required />
<input type="button" id="btn" value="ok" />
</form>

file.js file.js

$(document).ready(function (){    
$("#form1").validate({
    rules: {
        name: "required"
    },
    messages: {
        name: "Please specify your name"

    }
})

$('#btn').click(function() {
    $("#form1").valid();
});

});

Check this and note how the scripts are included: 对此进行检查并注意如何包含脚本:

 $(document).ready(function (){ $("#form1").validate({ rules: { name: "required" }, messages: { name: "Please specify your name" } }); $('#btn').click(function() { $("#form1").valid(); }); }); 
 #form1 label.error { color: #FB3A3A; display: block; margin: 10px; padding: 0; text-align: left; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.13.1/jquery.validate.min.js"></script> <form id="form1"> <label for="name">First Name</label> <input type="text" name="name" required /> <input type="button" id="btn" value="ok" /> </form> 

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

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