关于登陆时用户名存入CooKie不起作用,请教帮看一下错误,谢谢!

我爱运动 2014-03-27 10:53:46
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>网站登陆</title>
<script type="text/javascript">
function SaveCookie()
{
var data=escape(document.getElementById("username").value);

var d=new Date();
d.setDate(d.getDate()+1);//1天内有效
document.cookie="data="+data+";expires="+d.toGMTString();
}
function ReadCookie()
{
var d="";
var match=document.cookie.match(/data=([^;]+);?/i);
if(match)
{
d=match[1];
document.getElementById("username").value=unescape(d);
}
}
window.onload=ReadCookie;
window.onunload=SaveCookie;
</script>

<script>
function test(){
document.getElementById("addBtn").onclick = openme();
}
</script>
</head>
<body onLoad="test()">
<style type="text/css">
body {
margin: 0px;padding:0
}
#div1 {
display: none;
position: absolute;
z-index: 1000;
height: 100%;
width: 100%;
background: #000000;
filter:Alpha(opacity=30);
}
#div2 {
display: none;
position: absolute;
height: 100%;
width: 100%;
padding-top: 10%;
z-index: 1001;
left: 0px;
top: 0px;
}
</style>
<script>
function openme(){
document.getElementById('div1').style.display='block';
document.getElementById('div2').style.display='block';
}
function closeme(){
document.getElementById('div1').style.display='none';
document.getElementById('div2').style.display='none';
}
function logo_in(){alert()
//验证
//转向...
//myform.action=""
//login.submit()
closeme();
}
</script>
<script language="javascript">
function KeyDown()
{
if(event.keyCode==13)
{
document.login.submit();
}
}
</script>
<div id="div1"></div>
<div id="div2">
<table width="20%" border="0" cellpadding="0" cellspacing="1" style="background: #0043cf; position:static;filter:progid:DXImageTransform.Microsoft.DropShadow(color=#CCCCCC,offX=4,offY=4,positives=true)" align="center">
<tr id="m_tr">
<td height="33" background="images/Main_Line.gif"><table width="100%" height="33" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><font color="#0043cf"> <strong>欢迎登陆:</strong></font></td>
<td width="33"><input align="absMiddle" id="image2" name="image2" src="images/close_0.png" type="image" WIDTH="27" HEIGHT="27" onClick="closeme()" style="cursor: hand;"></td>
</tr>
</table></td>
</tr>
<tr>
<form name="login" method="post" action="index.asp">
<td width="100%" height="150" colspan="2" valign="top" bgcolor="#FFFFFF"><table width="100%" height="10"border="0" cellpadding="0" cellspacing="0">
<tr>
<td></td>
</tr>
</table>
<table width="100%" height="35" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="20"></td>
<td width="60">用户名:</td>
<td><input type="text" name="username" id="username" onKeyDown="KeyDown();" size="19" maxlength="20"></td>
</tr>
</table>
<table width="100%" height="10"border="0" cellpadding="0" cellspacing="0">
<tr>
<td></td>
</tr>
</table>
<table width="100%" height="35" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="20"></td>
<td width="60">密  码:</td>
<td><input name="password" size="19" type="password" maxlength="20" onKeyDown="KeyDown();"></td>
</tr>
</table>
<table width="100%" height="10"border="0" cellpadding="0" cellspacing="0">
<tr>
<td></td>
</tr>
</table>
<table width="100%" height="35" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="center"><input align="absMiddle" id="image1" name="image1" src="images/xmdl.jpg" type="image" WIDTH="60" HEIGHT="26"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
</div>
<div>
<input name="button" id="addBtn" type="hidden" value="" />
</div>
<div></div>
</body>
</html>
...全文
157 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
我爱运动 2014-03-27
  • 打赏
  • 举报
回复
感谢!showbo版主,解决了,我就是一直调试不行,谢了。加分!
Go 旅城通票 2014-03-27
  • 打赏
  • 举报
回复
不要设置body的onload事件,会覆盖window.onload事件,导致没有读cookie
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>网站登陆</title>
<script type="text/javascript">
    function SaveCookie() {
        var data = escape(document.getElementById("username").value);

        var d = new Date();
        d.setDate(d.getDate() + 1); //1天内有效
        document.cookie = "data=" + data + ";expires=" + d.toGMTString();
    }
    function ReadCookie() {
        var d = "";
        var match = document.cookie.match(/data=([^;]+);?/i);
        if (match) {
            d = match[1];
            document.getElementById("username").value = unescape(d);
        }
        openme()
    }
    window.onload = ReadCookie;
    window.onunload = SaveCookie;
</script>

</head>
<body>
<style type="text/css">
body {
margin: 0px;padding:0
}
#div1 {
display: none;
position: absolute;
z-index: 1000;
height: 100%;
width: 100%;
background: #000000;
filter:Alpha(opacity=30);
}
#div2 {
display: none;
position: absolute;
height: 100%;
width: 100%;
padding-top: 10%;
z-index: 1001;
left: 0px;
top: 0px;
}
</style>
<script>
    function openme() {
        document.getElementById('div1').style.display = 'block';
        document.getElementById('div2').style.display = 'block';
    }
    function closeme() {
        document.getElementById('div1').style.display = 'none';
        document.getElementById('div2').style.display = 'none';
    }
    function logo_in() {
        alert()
        //验证
        //转向...
        //myform.action=""
        //login.submit()
        closeme();
    }
</script>
<script language="javascript">
    function KeyDown() {
        if (event.keyCode == 13) {
            document.login.submit();
        }
    }
</script>
<div id="div1"></div>
<div id="div2">
<table width="20%" border="0" cellpadding="0" cellspacing="1" style="background: #0043cf; position:static;filter:progid:DXImageTransform.Microsoft.DropShadow(color=#CCCCCC,offX=4,offY=4,positives=true)" align="center">
<tr id="m_tr">
<td height="33" background="images/Main_Line.gif"><table width="100%" height="33" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td><font color="#0043cf"> <strong>欢迎登陆:</strong></font></td>
    <td width="33"><input align="absMiddle" id="image2" name="image2" src="images/close_0.png" type="image" WIDTH="27" HEIGHT="27" onClick="closeme()" style="cursor: hand;"></td>
  </tr>
</table></td>
</tr>
<tr>
<form name="login"  method="post" action="index.asp">
<td width="100%" height="150" colspan="2" valign="top" bgcolor="#FFFFFF"><table width="100%" height="10"border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td></td>
  </tr>
</table>
  <table width="100%" height="35" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="20"></td>
    <td width="60">用户名:</td>
    <td><input type="text" name="username" id="username" onKeyDown="KeyDown();" size="19" maxlength="20"></td>
  </tr>
</table>
  <table width="100%" height="10"border="0" cellpadding="0" cellspacing="0">
    <tr>
      <td></td>
    </tr>
  </table>
  <table width="100%" height="35" border="0" cellpadding="0" cellspacing="0">
    <tr>
      <td width="20"></td>
      <td width="60">密  码:</td>
      <td><input name="password" size="19" type="password" maxlength="20" onKeyDown="KeyDown();"></td>
    </tr>
</table>
  <table width="100%" height="10"border="0" cellpadding="0" cellspacing="0">
    <tr>
      <td></td>
    </tr>
  </table>
  <table width="100%" height="35" border="0" cellpadding="0" cellspacing="0">
    <tr>
      <td align="center"><input align="absMiddle" id="image1" name="image1" src="images/xmdl.jpg" type="image" WIDTH="60" HEIGHT="26"></td>
    </tr>
</table>
</td>
</form>
</tr>
</table>
</div>
<div>
<input name="button" id="addBtn" type="hidden" value="" />
</div>
<div></div>
</body>
</html>

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧