1.在静态页面里添加文本框及样式和js脚本的引用:
复制代码 代码如下:
Code highlighting produced by Actipro CodeHighlighter (freeware)https://www.jb51.net/-->
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>无标题页</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" />
</head>
<body>
<form id="form1" runat="server">
<div>
用户名:<input id="txtName" type="text" class ="txtName" />
<div id ="result"></div>
</div>
</form>
</body>
</html>
2.css样式表,当文本框文字为空时边框红色:
复制代码 代码如下:
.txtName
{
border:1px red solid;
}
3.js脚本:当文本框文字为空时边框红色;如果用户名为janes,则提示“用户名已经存在”,否则提示“用户名可以使用”。
复制代码 代码如下:
Code highlighting produced by Actipro CodeHighlighter (freeware)https://www.jb51.net/-->$(function(){
var txtname=$("#txtName");
//输入文字时文本框样式
txtname.keyup(function(){
var name=$(this).val();
if(name=="")
$(this).addClass("txtName");
else $(this).removeClass("txtName");
})
//失去焦点时验证用户名是否可用
$("#txtName").blur(function()
{
var name=$(this).val();
$.get("validator1.aspx?name="+name,null,function(response){
$("#result").html(response);
})
})
})
4..aspx及.cs页面代码,用来验证用户名是否可用,以返回结果。
复制代码 代码如下:
Code highlighting produced by Actipro CodeHighlighter (freeware)https://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("该用户名已经存在!");
else
Response.Write("该用户名可以使用!");
}
}
JQuery,无刷新,验证
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
更新日志
- 纪钧瀚《钢琴阅读时光 雨中书店聆听轻音乐》[FLAC/分轨][399.62MB]
- 证声音乐图书馆《走向自然 疗心爵士乐》[320K/MP3][87.4MB]
- 证声音乐图书馆《走向自然 疗心爵士乐》[FLAC/分轨][184.94MB]
- 陈慧娴.2018-Priscilla-Ism演唱会3CD(2024环球红馆40复刻系列)【环球】【WAV+CUE】
- 郑秀文.1999-我应该得到(国)【华纳】【WAV+CUE】
- 陈家慧.2011-钢琴酒吧2CD【龙吟唱片】【WAV+CUE】
- 证声音乐图书馆《雨季 蓝调吉他 Rainy Blues》[320K/MP3][45.01MB]
- 证声音乐图书馆《雨季 蓝调吉他 Rainy Blues》[FLAC/分轨][109.13MB]
- 赞多《序章》[320K/MP3][45.54MB]
- 许巍.2004-每一刻都是崭新的【步升大风】【WAV+CUE】
- 群星.2024-四方馆影视原声带【韶愔音乐】【FLAC分轨】
- 陈雷.1997-安锁咧【金圆唱片】【WAV+CUE】
- 关淑怡.2013-MY.FAVORITE.SK.3CD【环球】【WAV+CUE】
- Sweety.2006-花言乔语【丰华】【WAV+CUE】
- 李恕权.2003-回·20年全精选2CD【SONY】【WAV+CUE】