67,513
社区成员
发帖
与我相关
我的任务
分享
<script language="javascript" type="text/javascript">
$(function(){
$("#tb th").css({color:"#FFFFFF"});
//登录
$("#btnSubmit").click(function(){
if(checkUserName()&&checkPwd()&&checkCode()){
$("#loginForm").submit();
return true;
}else{
$("#msgResult").html("输入数据不合法!");
return false;
}
});
var reg=/^(?:[\u4e00-\u9fa5]*\w*\s*)+$/;
//用户名文本框失去焦点
$("#txtName").blur(function checkUserName(){
if($("#txtName").val()==""){
$("#txtName").css({backgroundColor:'red'});
$("#msgName").html("请输入用户名!");
return false;
}
if(!reg.test($("#txtName").val())){
$("#txtName").css({backgroundColor:'red'});
$("#msgName").html("不能有特殊字符!");
return false;
}
$("#msgName").html("");
$("#txtName").css({backgroundColor:''});
return true;
});
//密码文本框失去焦点
$("#txtPwd").blur(function checkPwd(){
if($("#txtPwd").val()==""){
$("#txtPwd").css({backgroundColor:'red'});
$("#msgPwd").html("请输入密码!");
return false;
}
if(!reg.test($("#txtPwd").val())){
$("#txtPwd").css({backgroundColor:'red'});
$("#msgPwd").html("不能有特殊字符!");
return false;
}
$("#msgPwd").html("");
$("#txtPwd").css({backgroundColor:''});
return true;
});
//验证码文本框失去焦点
$("#txtCode").blur(function checkCode(){
if($("#txtCode").val()==""){
$("#txtCode").css({backgroundColor:'red'});
$("#msgCode").html("请输入验证码!");
return false;
}
if(!reg.test($("#txtCode").val())){
$("#txtCode").css({backgroundColor:'red'});
$("#msgCode").html("错误的验证码!");
return false;
}
$("#msgCode").html("");
$("#txtCode").css({backgroundColor:''});
return true;
});
//键盘事件(这里是回车事件),验证通过则提交
$(document).keydown(function(event) {
if(event.keyCode == 13&& checkUserName()&& checkPwd()&&checkCode()) {
$("#loginForm").submit();
}
});
});
//更换验证码
function ChangeCode(obj){
obj.src=obj.src+"?temp=" + (new Date().getTime().toString(36));;
}
</script>
form表单:
<s:form id="loginForm" action="user_manager_doLogin.action"
method="post">
<div style="margin: 5px">
<img src="${pageContext.request.contextPath}/images/login.jpg" title="欢迎登录"/>
</div>
<hr size="2" color="#FFFFFF" />
<table width="100%" border="0" id="tb" cellspacing="5"
cellpadding="0">
<tr>
<th width="35%" align="right">
账 号:
</th>
<td width="65%" align="left">
<s:textfield name="userItem.usrName" id="txtName"></s:textfield>
<span id="msgName" style="color: #FF0000; font-size: 12px"></span>
</td>
</tr>
<tr>
<th align="right">
密 码:
</th>
<td align="left">
<s:password id="txtPwd" name="userItem.usrPassword" size="21"
maxlength="20" onselectstart="return false;"
ondragenter="return false;" onpaste="return false;"></s:password>
<span id="msgPwd" style="color: #FF0000; font-size: 12px"></span>
</td>
</tr>
<tr>
<th align="right">
验证码:
</th>
<td align="left">
<s:textfield id="txtCode" name="code" size="5"></s:textfield>
<img style="cursor: pointer;"
src="${pageContext.request.contextPath}/servlet/CodeImage"
alt="点击,更换验证码" onclick="ChangeCode(this);" />
<span id="msgCode" style="color: #FF0000; font-size: 12px"></span>
</td>
</tr>
<tr>
<td>
</td>
<td align="left">
<input type="checkbox" name="rememberMe" id="checkbox" />
<label for="checkbox" style="color: #FFFFFF;">
1周内不用再登录
</label>
</td>
</tr>
<tr>
<td>
</td>
<td align="left">
<input type="button" id="btnSubmit" value="登录"
style="background-color: #1C5BA6; border: #FFFFFF 1px solid; color: #FFFFFF" />
<input type="reset" id="btnCancel" value="取消"
style="background-color: #1C5BA6; border: #FFFFFF 1px solid; color: #FFFFFF" />
<span id="msgResult" style="color: #FF0000; font-size: 12px"></span>
</td>
</tr>
</table>
</s:form>