87,992
社区成员
发帖
与我相关
我的任务
分享function checkUserName(name) {
var $a = $("#" + name);
if ($a.val() == '' || $a == null || typeof $a === 'undefined') {
$a.siblings('span').text("用户名不能为空").css("display", "inline-block");
}
else {
if ($a.val().length < 5) {
$a.siblings('span').text("用户名长度至少为5位").css("display", "inline-block");
}
else if ($a.val().length > 20) {
$a.siblings('span').text("用户名长度至多为20位").css("display", "inline-block");
}
else {
$a.siblings('span').text("用户名合法").css("display", "inline-block").css("color","green");
}
}
}


<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4.min.js"></script>
<script src="t.js"></script>
<h2>
用户登录</h2>
<p>
<label for="userName">
用户名:</label><input type="text" name="userName" id="userName" /><em>*</em><span>用户名不能为空</span><input type="button" value="检查" onclick="checkUserName('userName')"/>
</p>
<p>
<label for="userPassword">
密码:</label><input type="password" name="userPassword" id="userPassword" /><em>*</em><span>密码不能为空</span>
</p>
<p>
<label for="validate">
验证码:</label><input type="text" name="validate" id="validate" /><img src="/Validate/validata_code.aspx"
alt="验证码不区分大小写" onclick="this.src=this.src+'?'" /><em>*</em><span>验证码不正确</span>
</p>
<p>
<label for="mLogin">
记住密码:</label><input type="checkbox" name="mLogin" id="mLogin" />2周内免登录
</p>
<input type="button" value="检查" onclick="checkUserName('test')"/>
<script language="javascript" type="text/javascript">
</script>$().ready(function () {
focus('userName');
// focus('userPassword');
// focus('validate');
// checkUserName('userName');
$("#userName").blur(function () {
checkUserName('userName');
});
$("#userPassword").blur(function () {
checkPassWord('userPassword');
});
$("#validate").blur(function () {
checkEmail('validate');
});
});
function focus(idName) {
$("#" + idName).bind("focus", function () {
$(this).css("outline", "1px solid aqua");
}).bind("blur", function () {
$(this).css("outline", "0px solid aqua");
});
}
function checkUserName(idName) {
var $a = $("#" + idName);
alert($a.val());
alert($a.val().length);
if ($a.val() == '' || $a == null || typeof $a === 'undefined') {
$a.siblings('span').text("用户名不能为空").css("display", "inline-block");
}
else {
if ($a.val().length < 5)
$a.siblings('span').text("用户名不能少于5位").css("display", "inline-block");
else if ($a.val().length > 20)
$a.siblings('span').text("用户名不能至多5位").css("display", "inline-block");
else {
$a.siblings('span').text("用户名合法").css("display", "inline-block").css("color", "green");
}
}
}
function checkPassWord(idName) {
var $b = $("#" + idName);
if ($b.val() == '' || $b == null || typeof $b === 'undefined') {
$b.siblings('span').text("密码不能为空").css("display", "inline-block");
}
else {
if ($b.val().length < 5)
$b.siblings('span').text("密码不能少于5位").css("display", "inline-block");
else {
$b.siblings('span').text("密码名合法").css("display", "inline-block").css("color", "green");
}
}
}
function checkEmail(idName) {
var $c = $("#" + idName);
if ($c.val() == '' || $c == null || typeof $c === 'undefined') {
$c.siblings('span').text("验证码不能为空").css("display", "inline-block");
}
else {
if ($c.val().toUpperCase() != GLOBAL.cookie.read('validate')) {
$c.siblings('span').text("验证码不正确").css("display", "inline-block");
} else {
$c.siblings('span').text("验证码正确").css("display", "inline-block").css("color", "green"); ;
}
}
}

<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4.min.js"></script>
<h2>
用户登录</h2>
<p>
<label for="userName">
用户名:</label><input type="text" name="userName" id="userName" /><em>*</em><span>用户名不能为空</span><input type="button" value="检查" onclick="checkUserName('userName')"/>
</p>
<p>
<label for="userPassword">
密码:</label><input type="password" name="userPassword" id="userPassword" /><em>*</em><span>密码不能为空</span>
</p>
<p>
<label for="validate">
验证码:</label><input type="text" name="validate" id="validate" /><img src="/Validate/validata_code.aspx"
alt="验证码不区分大小写" onclick="this.src=this.src+'?'" /><em>*</em><span>验证码不正确</span>
</p>
<p>
<label for="mLogin">
记住密码:</label><input type="checkbox" name="mLogin" id="mLogin" />2周内免登录
</p>
<input type="button" value="检查" onclick="checkUserName('test')"/>
<script language="javascript" type="text/javascript">
$().ready(function () {
focus('userName');
// focus('userPassword');
// focus('validate');
// checkUserName('userName');
$("#userName").blur(function () {
checkUserName('userName');
});
$("#userPassword").blur(function () {
checkPassWord('userPassword');
});
$("#validate").blur(function () {
checkEmail('validate');
});
});
function focus(idName) {
$("#" + idName).bind("focus", function () {
$(this).css("outline", "1px solid aqua");
}).bind("blur", function () {
$(this).css("outline", "0px solid aqua");
});
}
function checkUserName(idName) {
var $a = $("#" + idName);
alert($a.val());
alert($a.val().length);
if ($a.val() == '' || $a == null || typeof $a === 'undefined') {
$a.siblings('span').text("用户名不能为空").css("display", "inline-block");
}
else {
if ($a.val().length < 5)
$a.siblings('span').text("用户名不能少于5位").css("display", "inline-block");
else if ($a.val().length > 20)
$a.siblings('span').text("用户名不能至多5位").css("display", "inline-block");
else {
$a.siblings('span').text("用户名合法").css("display", "inline-block").css("color", "green");
}
}
}
function checkPassWord(idName) {
var $b = $("#" + idName);
if ($b.val() == '' || $b == null || typeof $b === 'undefined') {
$b.siblings('span').text("密码不能为空").css("display", "inline-block");
}
else {
if ($b.val().length < 5)
$b.siblings('span').text("密码不能少于5位").css("display", "inline-block");
else {
$b.siblings('span').text("密码名合法").css("display", "inline-block").css("color", "green");
}
}
}
function checkEmail(idName) {
var $c = $("#" + idName);
if ($c.val() == '' || $c == null || typeof $c === 'undefined') {
$c.siblings('span').text("验证码不能为空").css("display", "inline-block");
}
else {
if ($c.val().toUpperCase() != GLOBAL.cookie.read('validate')) {
$c.siblings('span').text("验证码不正确").css("display", "inline-block");
} else {
$c.siblings('span').text("验证码正确").css("display", "inline-block").css("color", "green"); ;
}
}
}
</script><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题页</title>
</head>
<body>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4.min.js"></script>
<h2>
用户登录</h2>
<p>
<label for="userName">
用户名:</label><input type="text" name="userName" id="userName" /><em>*</em><span>用户名不能为空</span>
</p>
<p>
<label for="userPassword">
密码:</label><input type="password" name="userPassword" id="userPassword" /><em>*</em><span>密码不能为空</span>
</p>
<p>
<label for="validate">
验证码:</label><input type="text" name="validate" id="validate" /><img src="/Validate/validata_code.aspx"
alt="验证码不区分大小写" onclick="this.src=this.src+'?'" /><em>*</em><span>验证码不正确</span>
</p>
<p>
<label for="mLogin">
记住密码:</label><input type="checkbox" name="mLogin" id="mLogin" />2周内免登录
</p>
<script language="javascript" type="text/javascript">
$().ready(function () {
focus('userName');
// focus('userPassword');
// focus('validate');
// checkUserName('userName');
$("#userName").blur(function () {
checkUserName('userName');
});
$("#userPassword").blur(function () {
checkPassWord('userPassword');
});
$("#validate").blur(function () {
checkEmail('validate');
});
});
function focus(idName) {
$("#" + idName).bind("focus", function () {
$(this).css("outline", "1px solid aqua");
}).bind("blur", function () {
$(this).css("outline", "0px solid aqua");
});
}
function checkUserName(idName) {
var $a = $("#" + idName);
if ($a.val() == '' || $a == null || typeof $a === 'undefined') {
$a.siblings('span').text("用户名不能为空").css("display", "inline-block");
}
else {
if ($a.val().length < 5)
$a.siblings('span').text("用户名不能少于5位").css("display", "inline-block");
else if ($a.val().length > 20)
$a.siblings('span').text("用户名不能至多5位").css("display", "inline-block");
else {
$a.siblings('span').text("用户名合法").css("display", "inline-block").css("color", "green");
}
}
}
function checkPassWord(idName) {
var $b = $("#" + idName);
if ($b.val() == '' || $b == null || typeof $b === 'undefined') {
$b.siblings('span').text("密码不能为空").css("display", "inline-block");
}
else {
if ($b.val().length < 5)
$b.siblings('span').text("密码不能少于5位").css("display", "inline-block");
else {
$b.siblings('span').text("密码名合法").css("display", "inline-block").css("color", "green");
}
}
}
function checkEmail(idName) {
var $c = $("#" + idName);
if ($c.val() == '' || $c == null || typeof $c === 'undefined') {
$c.siblings('span').text("验证码不能为空").css("display", "inline-block");
}
else {
if ($c.val().toUpperCase() != GLOBAL.cookie.read('validate')) {
$c.siblings('span').text("验证码不正确").css("display", "inline-block");
} else {
$c.siblings('span').text("验证码正确").css("display", "inline-block").css("color", "green"); ;
}
}
}
</script>
</body>
</html>
<h2>
用户登录</h2>
<p>
<label for="userName">
用户名:</label><input type="text" name="userName" id="userName" /><em>*</em><span>用户名不能为空</span>
</p>
<p>
<label for="userPassword">
密码:</label><input type="password" name="userPassword" id="userPassword" /><em>*</em><span>密码不能为空</span>
</p>
<p>
<label for="validate">
验证码:</label><input type="text" name="validate" id="validate" /><img src="/Validate/validata_code.aspx"
alt="验证码不区分大小写" onclick="this.src=this.src+'?'" /><em>*</em><span>验证码不正确</span>
</p>
<p>
<label for="mLogin">
记住密码:</label><input type="checkbox" name="mLogin" id="mLogin" />2周内免登录
</p>
$().ready(function () {
focus('userName');
// focus('userPassword');
// focus('validate');
// checkUserName('userName');
$("#userName").blur(function () {
checkUserName('userName');
});
$("#userPassword").blur(function () {
checkPassWord('userPassword');
});
$("#validate").blur(function () {
checkEmail('validate');
});
});
function focus(idName) {
$("#" + idName).bind("focus", function () {
$(this).css("outline", "1px solid aqua");
}).bind("blur", function () {
$(this).css("outline", "0px solid aqua");
});
}
function checkUserName(idName) {
var $a = $("#" + idName);
if ($a.val() == '' || $a == null || typeof $a === 'undefined') {
$a.siblings('span').text("用户名不能为空").css("display", "inline-block");
}
else {
if ($a.val().length < 5)
$a.siblings('span').text("用户名不能少于5位").css("display", "inline-block");
else if ($a.val().length > 20)
$a.siblings('span').text("用户名不能至多5位").css("display", "inline-block");
else {
$a.siblings('span').text("用户名合法").css("display", "inline-block").css("color", "green");
}
}
}
function checkPassWord(idName) {
var $b = $("#" + idName);
if ($b.val() == '' || $b == null || typeof $b === 'undefined') {
$b.siblings('span').text("密码不能为空").css("display", "inline-block");
}
else {
if ($b.val().length < 5)
$b.siblings('span').text("密码不能少于5位").css("display", "inline-block");
else {
$b.siblings('span').text("密码名合法").css("display", "inline-block").css("color", "green");
}
}
}
function checkEmail(idName) {
var $c = $("#" + idName);
if ($c.val() == '' || $c == null || typeof $c === 'undefined') {
$c.siblings('span').text("验证码不能为空").css("display", "inline-block");
}
else {
if ($c.val().toUpperCase() != GLOBAL.cookie.read('validate')) {
$c.siblings('span').text("验证码不正确").css("display", "inline-block");
} else {
$c.siblings('span').text("验证码正确").css("display", "inline-block").css("color", "green"); ;
}
}
}$().ready(function () {
focus('userName');
// focus('userPassword');
// focus('validate');
// checkUserName('userName');
// $("#userName").blur(function () {
// checkUserName('userName');
// });
$("#userPassword").blur(function () {
checkPassWord('userPassword');
});
$("#validate").blur(function () {
checkEmail('validate');
});
});
function focus(idName) {
$("#" + idName).bind("focus", function () {
$(this).css("outline", "1px solid aqua");
}).bind("blur", function () {
$(this).css("outline", "0px solid aqua");
});
}
//function checkUserName(idName) {
// var $a = $("#" + idName);
// if ($a.val() == '' || $a == null || typeof $a === 'undefined') {
// $a.siblings('span').text("用户名不能为空").css("display", "inline-block");
// }
// else {
// if ($a.val().length < 5)
// $a.siblings('span').text("用户名不能少于5位").css("display", "inline-block");
// else if ($a.val().length > 20)
// $a.siblings('span').text("用户名不能至多5位").css("display", "inline-block");
// else {
// $a.siblings('span').text("用户名合法").css("display", "inline-block").css("color", "green");
// }
// }
//}
function checkPassWord(idName) {
var $b = $("#" + idName);
if ($b.val() == '' || $b == null || typeof $b === 'undefined') {
$b.siblings('span').text("密码不能为空").css("display", "inline-block");
}
else {
if ($b.val().length < 5)
$b.siblings('span').text("密码不能少于5位").css("display", "inline-block");
else {
$b.siblings('span').text("密码名合法").css("display", "inline-block").css("color", "green");
}
}
}
function checkEmail(idName) {
var $c = $("#" + idName);
if ($c.val() == '' || $c == null || typeof $c === 'undefined') {
$c.siblings('span').text("验证码不能为空").css("display", "inline-block");
}
else {
if ($c.val().toUpperCase() != GLOBAL.cookie.read('validate')) {
$c.siblings('span').text("验证码不正确").css("display", "inline-block");
} else {
$c.siblings('span').text("验证码正确").css("display", "inline-block").css("color", "green"); ;
}
}
}
$().ready(function () {
focus('userName');
// focus('userPassword');
// focus('validate');
// checkUserName('userName');
$("#userPassword").blur(function () {
checkUserName('userPassword');
});
$("#userPassword").blur(function () {
checkPassWord('userPassword');
});
$("#validate").blur(function () {
checkEmail('validate');
});
});
function focus(idName) {
$("#" + idName).bind("focusin", function () {
$(this).css("outline", "1px solid aqua");
}).bind("blur", function () {
$(this).css("outline", "0px solid aqua");
});
}
function checkUserName(idName) {
var $a = $("#" + idName);
if ($a.val() == '' || $a == null || typeof $a === 'undefined') {
$a.siblings('span').text("用户名不能为空").css("display", "inline-block");
}
else {
if ($a.val().length < 5)
$a.siblings('span').text("用户名不能少于5位").css("display", "inline-block");
else if ($a.val().length > 20)
$a.siblings('span').text("用户名不能至多5位").css("display", "inline-block");
else {
$a.siblings('span').text("用户名合法").css("display", "inline-block").css("color", "green");
}
}
}
function checkPassWord(idName) {
var $b = $("#" + idName);
if ($b.val() == '' || $b == null || typeof $b === 'undefined') {
$b.siblings('span').text("密码不能为空").css("display", "inline-block");
}
else {
if ($b.val().length < 5)
$b.siblings('span').text("密码不能少于5位").css("display", "inline-block");
else {
$b.siblings('span').text("密码名合法").css("display", "inline-block").css("color", "green");
}
}
}
function checkEmail(idName) {
var $c = $("#" + idName);
if ($c.val() == '' || $c == null || typeof $c === 'undefined') {
$c.siblings('span').text("验证码不能为空").css("display", "inline-block");
}
else {
if ($c.val().toUpperCase() != GLOBAL.cookie.read('validate')) {
$c.siblings('span').text("验证码不正确").css("display", "inline-block");
} else {
$c.siblings('span').text("验证码正确").css("display", "inline-block").css("color", "green"); ;
}
}
}