Ajax jquery verifies whether the user has registered demo code _ajax related

Source: Internet
Author: User
Service-side code there's no
.




HTML code is simpler and needs to be introduced into the jquery library


Copy Code code as follows:

<body>
Please enter user name: <input type= "text" id= "UserName" class= "Usertext"/> <input "button" type= "checksum" value= "id=" />
<div id= "Result" ></div>
</body>



JS Code


Copy Code code as follows:

/*
* Register these jobs when page load is complete
* */
$ (document). Ready (function () {
This is the code that needs to be executed after the page is loaded
var Usernamenode = $ ("#userName");
Need to find button press, register event
$ ("#verifyButton"). Click (function () {
1. Get the contents of the text box
var userName = Usernamenode.val ();
2. Send this content to server side
if (UserName = = "") {
Alert ("User name cannot be empty");
} else {
$.get ("http://127.0.0.1:8080/JQuery/UserVerify?userName=" + encodeURI (encodeURI (UserName)), Null,function ( Response) {
3. Receive server-side returned data, fill in div
$ ("#result"). HTML (response);
});

}
});
Need to find text box, register event
Usernamenode.keyup (function () {
Get the contents of the current text box
var value = Usernamenode.val ();
if (value = = "") {
Make the border red and take a background image
Usernamenode.addclass ("Usertext");
} else {
Remove borders and background images
Usernamenode.removeclass ("Usertext");

}
});
});



CSS style, so that when there is no content in the text box, the border is red and there is a red wave underneath it


Copy Code code as follows:

. usertext {
/* Control the border of the text box is a red solid line * *
border:1px solid red;
Background-image:url (.. /images/userverify.gif);
Background-repeat:repeat-x;
Background-position:bottom;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.