Home >Web Front-end >JS Tutorial >A small example of JQuery implementing user name non-refresh verification_jquery

A small example of JQuery implementing user name non-refresh verification_jquery

WBOY
WBOYOriginal
2016-05-16 17:39:39994browse

1. Add text boxes, styles and js script references to the static page:

Copy code The code is as follows:

Code highlighting produced by Actipro CodeHighlighter (freeware)http:/ /www.jb51.net/-->


Untitled page





 

                         <







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

.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, it will prompt "the user name already exists", otherwise it will prompt "the user name can be used".

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 whether the username is available when losing focus
$("# txtName").blur(function()
{
var name=$(this).val();
$.get("validator1.aspx?name=" name,null,function(response ){
$("#result").html(response);
})

})

})



4..aspx and .cs page codes are used to verify whether the user name is available to return the result.

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("This user Name already exists! ");
else
Response.Write("This username can be used!");

}
}


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:How to obtain the URL of this file upload in multiple forms and implement js code_javascript skillsNext article:How to obtain the URL of this file upload in multiple forms and implement js code_javascript skills

Related articles

See more