HTML Header reference:
<script type= "Text/javascript" src= ". /js/jquery-1.3.2.min.js "></script>
<script type=" Text/javascript "src=". /js/jquery.validate.min.js "></script>
<script type=" Text/javascript "src=". /js/messages_cn.js "></script>
HTML content (partial):
<form name= "Form1" Id= "Form1" method= "Post" action= "" >
<dl>
<dt> user name:</dt>
< Dd><input name= "txtUserName" id= "txtUserName" type= "text" class= "input1"/></dd>
</dl>
</form>
JS Code section:
$ (function () {//form validation js $ ("#form1"). Validate ({//tags added when error errorelement: span)
Rules: {txtusername: {required:true, Minlength:3, maxlength:16, remote: {
Type: "Post", url: "/tools/validateusername.ashx", data: {username:function () {
Return $ ("#txtUserName"). Val ();
}, DataType: "HTML", datafilter:function (data, type) {if (data = "true")
return true;
else return false;
Success:function (label) {//the correct style Label.text (""). AddClass ("Success"); Messages: {txtusername: {required: "Please enter the username, 3-16 characters (Letters, numbers, underscores), cannot change after registration, minlength:" User name length cannot be
Less than 3 characters ", MaxLength:" User name length can not be greater than 16 characters, Remote: "User name is not available"}});
});
Place to be noted:
Data: {
username:function () {return
$ ("#txtUserName"). Val ();
There is a return value, if “data: {username: $("#txtUserName").val();}”, it is written directly this is not getting the value.
The above is a small set to introduce the use of Jquery.validate asynchronous authentication user name exists, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!