重点js: //唐初登陆框 function testMessageBox(ev) { var objPos = mousePosition(ev); var cont = '<div id="abcd"><form action="<%=path%>/sys/login.action" name="loginSubmit" id="login_form" method="post"><div id="login"><div class="login_info"><dl> <dt>用户名</dt><dd><input name="user.userName" type="text" class="input1 inputimg1" id="loginUser" /><div class="clear" style="color: red" align="center" id="showName"></div></dd></dl><dl> <dt>密码</dt> <dd><input name="user.password" type="password" class="input1" id="pwd"/> <div class="clear" style="color: red" align="center" id="showpwd"></div></dd></dl><dl><dt><input type="checkbox" value="" style="float:left;" id="log" onclick="checkLogin(this)"/>自动登录 <a href="#" class="colorblue">忘记密码?</a></dt><dd><input name="" type="button" class="login_ok" id="loginSubmit" onclick="loginClick()"/></dd><div class="clear" style="color: red" align="center" id="umessagelogin"></div></dl></div></div></form></div>'; messContent=cont; showMessageBox('<h5>用户登录<font class="login_span">您如果还没账号,请点击 <a href="/sys/toRegistration.action" class="colorblue">注册</a></font></h5>',messContent,objPos,700); } //登录处理的一些js //登录按钮 function loginClick(){ if(checkValidate()==true){ $('#login_form').submit(); } $(document).bind("keydown", function(event){ if(event.keyCode == 13 && checkValidate()==true){ $('#login_form').submit(); } }); } //自动登录 function checkLogin(obj) { if (obj.checked == true && checkValidate()==true) { $('#login_form').submit(); } } //输入验证 function checkValidate(){ //用户名 var userName=$("#loginUser").val(); if(!(/^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.){1,4}[a-z]{2,3}$/).test(userName)){ $("#showName").html("邮箱格式不正确"); return false; }else{ $("#showName").html(""); } //密码 var pwd=$("#pwd").val(); if($.trim(pwd)==""){ $("#showpwd").html("密码不能为空"); return false; }else{ $("#showpwd").html(""); } submitForm(); return true; } function submitForm(){ $('#login_form').form({ onSubmit: function(){ return true; }, success:function(data){ var value = eval("(" + data + ")"); if(value.result=='success'){ $("#umessagelogin").html("登录成功"); setTimeout(function(){ window.location.href='<%=request.getContextPath()%>/index.jsp'; }, 2000); } else if (value.result='msg'){ $("#umessagelogin").html("用户不存在"); }else if (value.result='error'){ $("#umessagelogin").html("系统异常"); } } }); } 页面调用位置: <span onclick="testMessageBox(event);" >登录</span>