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!") ");
}
}