簡體   English   中英

使用Jquery驗證來驗證表單

[英]Validate form with Jquery validation

我想驗證我的表格,但是出現了這個錯誤:

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

我包括了js文件驗證jquery-validate.min.js和jquery-validate.js。

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

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

    }
})

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

});

對此進行檢查並注意如何包含腳本:

 $(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