jquery implementation of user name without refreshing validation of a small example _jquery

Source: Internet
Author: User

1. Add a text box and a reference to the style and JS script on the static page:

Copy Code code as follows:

Code highlighting produced by Actipro Codehighlighter (freeware) http://www.jb51.net/-->
<title> Untitled Page </title>
<script language = "javascript" src = ". /jquery-1.3.2.min.js "type = Text/javascript" ></script>
<script language = "javascript" src = "validator.js" type = "Text/javascript" ></script>
<link type = "Text/css" rel= "stylesheet" href = "validator.css"/>
<body>
<form id= "Form1" runat= "Server" >
<div>
User name: <input id= "txtname" type= "text" class = "txtname"/>
<div id = "Result" ></div>
</div>
</form>
</body>

2.CSS style sheet, red border when text box text is empty:

Copy Code code as follows:

. txtname
{
BORDER:1PX Red Solid;
}

3.js script: When the text box text is empty, the border is red, if the user name is Janes, prompt "username already exists", otherwise prompt "user name can use".

Copy Code code as follows:

Code highlighting produced by Actipro Codehighlighter (freeware) http://www.jb51.net/-->$ (function () {
var txtname=$ ("#txtName");
text box style when entering text
Txtname.keyup (function () {
var name=$ (this). Val ();
if (name== "")
$ (this). addclass ("txtname");
else $ (this). Removeclass ("txtname");
})
Verify that the user name is available when the focus is lost
$ ("#txtName"). blur (Function ()
{
var name=$ (this). Val ();
$.get ("Validator1.aspx?name=" +name,null,function (response) {
$ ("#result"). HTML (response);
})

})
})

4..aspx and. CS page code to verify that the user name is available to return the result.

Copy Code code as follows:

Code highlighting produced by Actipro Codehighlighter (freeware) Http://www.jb51.net/-->public partial class Validator_validator1:System.Web.UI.Page
{
protected void Page_Load (object sender, EventArgs e)
{
String name = request.querystring["Name"]. ToString ();
if (name = = "Janes")
Response.Write ("The username already exists!") ");
Else
Response.Write ("This user name can be used!") ");

}
}

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.