Jquery-登陆界面及validate登陆用户验证

效果图

HTML代码:

	<div id="login">
			<h1>Log In</h1>
			<fieldset id="inputs">
				UserName:
					<input id="userName" class="username" type="text" runat="server" />
				PassWord:
					<input id="passWord" class="password" type="password" runat="server" />
				<div class="tipinfo"></div>
			</fieldset>
			<fieldset id="actions" style="float: right">
				<asp:Button ID="btnLogin" CssClass="submit" runat="server" Text="Log in"
					OnClientClick="ValidateLogin();" OnClick="btnLogin_Click" />
			</fieldset>
		</div>

CSS代码:

html, body {
	width: 100%;
	height: 100%;
	padding: 0;
	background: #fff;
	margin: 0;
	font-family: arial;
}

body {
	font: 12px 'Lucida Sans Unicode', 'Trebuchet MS', Arial, Helvetica;
	margin: 0;
	background-color: #d9dee2;
	height: 100%;
	background-image: -webkit-gradient(linear, left top, left bottom, from(#ebeef2), to(#d9dee2));
	background-image: -webkit-linear-gradient(top, #ebeef2, #d9dee2);
	background-image: -moz-linear-gradient(top, #ebeef2, #d9dee2);
	background-image: -ms-linear-gradient(top, #ebeef2, #d9dee2);
	background-image: -o-linear-gradient(top, #ebeef2, #d9dee2);
	background-image: linear-gradient(top, #ebeef2, #d9dee2);
}



/* 错误提示 */
.tipinfo {
	float: left;
}

.tipinfo font.error {
		background: url("../images/unchecked.jpg") no-repeat left;
		padding-left: 17px;
		color: #eb0000;
		width: 300px;
		display: block;
	}

.tipinfo font.valid {
		background: url("../images/checked.gif") no-repeat left;
		width: 14px;
		height: 13px;
		overflow: hidden;
		padding: 0;
		margin: 5px 0 0 5px;
		display: inline-block;
	}


/*登陆css*/
#login {
	background-color: #fff;
	background-image: -webkit-gradient(linear, left top, left bottom, from(#fff), to(#eee));
	background-image: -webkit-linear-gradient(top, #fff, #eee);
	background-image: -moz-linear-gradient(top, #fff, #eee);
	background-image: -ms-linear-gradient(top, #fff, #eee);
	background-image: -o-linear-gradient(top, #fff, #eee);
	background-image: linear-gradient(top, #fff, #eee);
	height: 270px;
	width: 400px;
	margin: -150px 0 0 -230px;
	padding: 30px;
	position: absolute;
	top: 45%;
	left: 50%;
	z-index: 0;
	-moz-border-radius: 3px;
	-webkit-border-radius: 3px;
	border-radius: 3px;
	-webkit-box-shadow: 0 0 2px rgba(0, 0, 0, 0.2), 0 1px 1px rgba(0, 0, 0, .2), 0 3px 0 #fff, 0 4px 0 rgba(0, 0, 0, .2),
 0 6px 0 #fff, 0 7px 0 rgba(0, 0, 0, .2);
	-moz-box-shadow: 0 0 2px rgba(0, 0, 0, 0.2), 1px 1px 0 rgba(0, 0, 0, .1), 3px 3px 0 rgba(255, 255, 255, 1), 
4px 4px 0 rgba(0, 0, 0, .1), 6px 6px 0 rgba(255, 255, 255, 1), 7px 7px 0 rgba(0, 0, 0, .1);
	box-shadow: 0 0 2px rgba(0, 0, 0, 0.2), 0 1px 1px rgba(0, 0, 0, .2), 0 3px 0 #fff, 0 4px 0 rgba(0, 0, 0, .2),
 0 6px 0 #fff, 0 7px 0 rgba(0, 0, 0, .2);
}

#login:before {
		content: '';
		position: absolute;
		z-index: -1;
		border: 1px dashed #ccc;
		top: 5px;
		bottom: 5px;
		left: 5px;
		right: 5px;
		-moz-box-shadow: 0 0 0 1px #fff;
		-webkit-box-shadow: 0 0 0 1px #fff;
		box-shadow: 0 0 0 1px #fff;
	}

h1 {
	text-shadow: 0 1px 0 rgba(255, 255, 255, .7), 0px 2px 0 rgba(0, 0, 0, .5);
	text-transform: uppercase;
	text-align: center;
	color: #666;
	margin: 0 0 30px 0;
	letter-spacing: 4px;
	font: normal 26px/1 Verdana, Helvetica;
	position: relative;
}

h1:after, h1:before {
		background-color: #777;
		content: "";
		height: 1px;
		position: absolute;
		top: 15px;
		width: 120px;
	}

h1:after {
		background-image: -webkit-gradient(linear, left top, right top, from(#777), to(#fff));
		background-image: -webkit-linear-gradient(left, #777, #fff);
		background-image: -moz-linear-gradient(left, #777, #fff);
		background-image: -ms-linear-gradient(left, #777, #fff);
		background-image: -o-linear-gradient(left, #777, #fff);
		background-image: linear-gradient(left, #777, #fff);
		right: 0;
	}

h1:before {
		background-image: -webkit-gradient(linear, right top, left top, from(#777), to(#fff));
		background-image: -webkit-linear-gradient(right, #777, #fff);
		background-image: -moz-linear-gradient(right, #777, #fff);
		background-image: -ms-linear-gradient(right, #777, #fff);
		background-image: -o-linear-gradient(right, #777, #fff);
		background-image: linear-gradient(right, #777, #fff);
		left: 0;
	}

fieldset {
	border: 0;
	padding: 0;
	margin: 0;
}

#inputs input {
	background: #f1f1f1 url(../images/login-sprite.png) no-repeat;
	padding: 15px 15px 15px 30px;
	margin: 0 0 10px 0;
	width: 353px; /* 353 + 2 + 45 = 400 */
	border: 1px solid #ccc;
	-moz-border-radius: 5px;
	-webkit-border-radius: 5px;
	border-radius: 5px;
	-moz-box-shadow: 0 1px 1px #ccc inset, 0 1px 0 #fff;
	-webkit-box-shadow: 0 1px 1px #ccc inset, 0 1px 0 #fff;
	box-shadow: 0 1px 1px #ccc inset, 0 1px 0 #fff;
}
/*用户名*/
.username {
	background-position: 5px -2px !important;
}
/*密码*/
.password {
	background-position: 5px -52px !important;
}

#inputs input:focus {
	background-color: #fff;
	border-color: #e8c291;
	outline: none;
	-moz-box-shadow: 0 0 0 1px #e8c291 inset;
	-webkit-box-shadow: 0 0 0 1px #e8c291 inset;
	box-shadow: 0 0 0 1px #e8c291 inset;
}

#actions {
	margin: 10px 0 0 0;
}

/*登陆按钮css*/
.submit {
	background-color: #ffb94b;
	background-image: -webkit-gradient(linear, left top, left bottom, from(#fddb6f), to(#ffb94b));
	background-image: -webkit-linear-gradient(top, #fddb6f, #ffb94b);
	background-image: -moz-linear-gradient(top, #fddb6f, #ffb94b);
	background-image: -ms-linear-gradient(top, #fddb6f, #ffb94b);
	background-image: -o-linear-gradient(top, #fddb6f, #ffb94b);
	background-image: linear-gradient(top, #fddb6f, #ffb94b);
	-moz-border-radius: 3px;
	-webkit-border-radius: 3px;
	border-radius: 3px;
	text-shadow: 0 1px 0 rgba(255,255,255,0.5);
	-moz-box-shadow: 0 0 1px rgba(0, 0, 0, 0.3), 0 1px 0 rgba(255, 255, 255, 0.3) inset;
	-webkit-box-shadow: 0 0 1px rgba(0, 0, 0, 0.3), 0 1px 0 rgba(255, 255, 255, 0.3) inset;
	box-shadow: 0 0 1px rgba(0, 0, 0, 0.3), 0 1px 0 rgba(255, 255, 255, 0.3) inset;
	border-width: 1px;
	border-style: solid;
	border-color: #d69e31 #e3a037 #d5982d #e3a037;
	float: left;
	height: 35px;
	padding: 0;
	width: 120px;
	cursor: pointer;
	font: bold 15px Arial, Helvetica;
	color: #8f5a0a;
}

.submit:hover, .submit:focus {
		background-color: #fddb6f;
		background-image: -webkit-gradient(linear, left top, left bottom, from(#ffb94b), to(#fddb6f));
		background-image: -webkit-linear-gradient(top, #ffb94b, #fddb6f);
		background-image: -moz-linear-gradient(top, #ffb94b, #fddb6f);
		background-image: -ms-linear-gradient(top, #ffb94b, #fddb6f);
		background-image: -o-linear-gradient(top, #ffb94b, #fddb6f);
		background-image: linear-gradient(top, #ffb94b, #fddb6f);
	}

.submit:active {
		outline: none;
		-moz-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5) inset;
		-webkit-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5) inset;
		box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5) inset;
	}

.submit::-moz-focus-inner {
		border: none;
	}

#actions a {
	color: #3151A2;
	float: right;
	line-height: 35px;
	margin-left: 10px;
}

CSS里面用到的图片:

checked.gif:  login-sprite.png:  unchecked.jpg:    

登陆验证JS代码:

 <script src="js/jquery-1.7.1.js"></script>
	<script src="js/jquery.validate.js"></script>
	<script>
		$(document).ready(function ()
		{
			$("#userName").focus();
		});
		function ValidateLogin()
		{
				//验证用户名       
				jQuery.validator.addMethod("userNameCheck", function (value, element) {
					return this.optional(element) || /^[a-zA-Z]\w{4,20}$/.test(value);
				}, "请输入4-20位字母开头的字母或数字和下划线");

			var validator = $("#form1").bind("invalid-form.validate", function () { }).validate
			({
				debug: true,
				onkeyup: false,
				errorElement: "font",
				errorPlacement: function (error, element) {
					error.appendTo(element.parent().find(".tipinfo"));
				},
				success: "valid",
				rules:
					{
						"userName": {required: true,userNameCheck: true},
						"passWord": { required: true, minlength: 1 }
					},
				messages:
					{
						"userName": {required: "请输入用户名",userNameCheck: "请输入4-20位字母开头的字母或数字和下划线"},
						"passWord": { required: "请输入密码", minlength: "密码长度至少为1位" }
					},
				submitHandler: function (form)
				{
					form.submit();
				}				
			});
		}
	</script>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值