---------------------------------------------------------------
<!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> <style type="text/css"> #loginui{ position:absolute; top:50%; left:50%; margin-top:-60px; margin-left:-150px; background-color:#3FF; } </style> <script src="CookieTools.js"></script> <script language="javascript"> function autologin() { var uid=getCookie("UserName"); var pwd=getCookie("Password"); if(uid!=""&&pwd!="") <!--符号 != 为不等于; "" 空--> { if(uid=="zs"&&pwd=="321")//再次自动登录判断是否符合 { location.href="viewExam.html"; } <!--如果用户输入正确则跳转到网页文件--> else{ document.getElementById("txtUID").value=uid; } <!--否则获得具体的txtUID的值--> } } autologin(); <!--调用与结束--> function login() { var uid=document.getElementById("txtUID").value; var pwd=document.getElementById("txtPWD").value; var auto=document.getElementById("ckLogin").checked; if(uid==""||pwd=="") { alert("用户名和口令都不能为空!"); return; } <!--读取文本框内容并进入判断循环,以上为判断是否为空--> if(auto==true){ setCookie("UserName",uid,30); setCookie("Password",pwd,30); } <!--cookie保存信息为30天--> if(uid=="zs"&&pwd=="321")//自动登录判断 { location.href="viewExam.html"; } <!--判断账户密码是否正确,则转跳到网页文件--> else { alert("用户名或口令不正确!"); } } <!--不正确就提示信息--> </script> <body> <form id="form1" name="form1" method="post" action=""> <div id="loginui"> <p>欢迎登录在线测试系统</p> <table width="300" border="0" cellspacing="0" cellpadding="0"> <tr> <td>用户名:</td> <td height="30"><label for="txtUID"></label> <input type="text" name="txtUID" id="txtUID" /></td> </tr> <tr> <td>口令:</td> <td height="30"><label for="txtPWD"></label> <input type="password" name="txtPWD" id="txtPWD" /></td> </tr> <tr> <td height="30" colspan="2"><input type="checkbox" name="ckLogin" id="ckLogin" /> <label for="ckLogin">一个月内自动登录</label></td> </tr> <tr> <td height="30" colspan="2"><input type="button" name="button" id="button" value="登录考试系统" onclick="login()" /></td> </tr> </table> </div> </form> </body> </html>cookieTools.js
------------------------------------------------
// JavaScript Document function setCookie(ckey, cvalue, exdays) { var d = new Date(); d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000)); //d.setDate(d.getDate()+exdays); var expires = "expires=" + d.toGMTString(); document.cookie = ckey + "=" + escape(cvalue) + "; " + expires; } function getCookie(ckey) {//获取指定名称的cookie的值 var arrStr = document.cookie.split("; "); for (var i = 0; i < arrStr.length; i++) { var pos=arrStr[i].indexOf("="); var key=arrStr[i].substr(0,pos);//取出=前面部分 if (key == ckey) return arrStr[i].substring(pos+1);//取出=后面的部分 } return ""; }zzzzzzzzzzz
Powered by ddoss.cn 12.0
©2015 - 2024 ddoss
渝公网安备50011302222260号 渝ICP备2024035333号 【实验平台安全承诺书】 小绿叶技术社区,优化网络中,点击查看配置信息
您的IP:192.168.122.82,2024-10-10 18:33:13,Processed in 0.02352 second(s).