| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 601 人关注过本帖
标题:用cookie实现记住内容?
只看楼主 加入收藏
流浪天边
Rank: 2
等 级:论坛游民
帖 子:100
专家分:53
注 册:2010-7-12
结帖率:79.31%
收藏
已结贴  问题点数:20 回复次数:2 
用cookie实现记住内容?
程序代码:
<html>
<head>
<title>
用cookie实现可记住表单
</title>
<!--脚本部分-->
<script>
function read_cookie(key){
var str,arry;
str=document.cookie;
arry=str.replace(/*;*/g,";").split(";");
key=escape(key)+"=";
for (i=0;i<arry.length;i++){
if(arry[i].indexOf(key)==0){
return(unescape(arry[i].split("=")[i]));
   }

 }
}
function write_cookie(key,value,cookiDomain,cookipath,cookieTimr,targetwindow)
var strAppendix="";
strAppendix += cookiDomain?";domain="+cookiDomain:"";
strAppendix += cookipath?";path="+cookipath:"";
strAppendix += expireTime?";expire="+expireTime:"";
targetwindow=targetwindow? targetwindow:top;
targetwindow.document.cookie=excape(key)+"="+excape(value)+strAppendix;
}
function loadDate(){
if(read_cookie("txt3"))$("txt3").value=read_cookie("txt3");
if(read_cookie("txt4"))$("txt4").value=read_cookie("txt4");
}
function saveDate(){
write_cookie("txt3",$("txt3").value);
write_cookie("txt4",$("txt4").value);
}
function $(str){return(document.getElementById(str));}
</script>
</head>
<body style="overflow:auto;" onload="loadDate";onunload="saveDate";>
<from>
<table>
<tr>
<td>普通文本框:</td>
<td><input id="text1"></td>
</tr>
<tr>
<td>普通文本框1:</td>
<td><input id="text2"></td>
</tr>
<tr>
<td>普通文本框2:</td>
<td><input id="text"></td>
<tr>
<td>普通文本框:</td>
<td><input id="text2"></td>
</tr>
<tr>
<td>可以记住内容文本框:</td>
<td><input id="text3"></td>
</tr>
<tr>
<td>可以记住内容文本框2:</td>
<td><input id="text4"></td>
</tr>
<td colspan="2">
<input name="sumbit" value="提交">
<input name="rest" value="重填">
<input name="button" value="查看cookie" onclick="alert(document.cookie);">
</body>
</html>
  我是菜鸟一个,对于调试程序很差劲,希望大家能帮我看看这个程序那里出错?
  如图:
  
图片附件: 游客没有浏览图片的权限,请 登录注册

  问题:提交和重填按钮没反应?
搜索更多相关主题的帖子: cookie 
2010-12-06 05:25
jianghong_02
Rank: 6Rank: 6
等 级:侠之大者
威 望:1
帖 子:143
专家分:476
注 册:2010-10-2
收藏
得分:20 
<html>
<head>
<title>
用cookie实现可记住表单
</title>
<!--脚本部分-->
<script language="javascript">
function read_cookie(key){
var str,arry;
str=document.cookie;
arry=str.replace(/*;*/g,";").split(";");
key=escape(key)+"=";
for (i=0;i<arry.length;i++){
if(arry[i].indexOf(key)==0){
return(unescape(arry[i].split("=")[i]));
   }
}
}
function write_cookie(key,value,cookiDomain,cookipath,cookieTimr,targetwindow)
var strAppendix="";
strAppendix += cookiDomain?";domain="+cookiDomain:"";
strAppendix += cookipath?";path="+cookipath:"";
strAppendix += expireTime?";expire="+expireTime:"";
targetwindow=targetwindow? targetwindow:top;
targetwindow.document.cookie=excape(key)+"="+excape(value)+strAppendix;
}
function loadDate(){
if(read_cookie("text3"))$("text3").value=read_cookie("text3");
if(read_cookie("text4"))$("text4").value=read_cookie("text4");
}
function saveDate(){
write_cookie("text3",$("text3").value);
write_cookie("text4",$("text4").value);
}
function $(str){return(document.getElementById(str));}
</script>
</head>
<body style="overflow:auto;" onload="loadDate" onUnload="saveDate">
<form>
<table>
<tr>
<td>普通文本框:</td>
<td><input id="text1"></td>
</tr>
<tr>
<td>普通文本框1:</td>
<td><input id="text2"></td>
</tr>
<tr>
<td>普通文本框2:</td>
<td><input id="text"></td>
</tr>
<tr>
<td>普通文本框:</td>
<td><input id="text2"></td>
</tr>
<tr>
<td>可以记住内容文本框:</td>
<td><input id="text3"></td>
</tr>
<tr>
<td>可以记住内容文本框2:</td>
<td><input id="text4"></td>
</tr>
<tr>
<td colspan="2">
<input name="sumbit"  value="提交" type="submit">
<input name="rest" value="重填" type="reset">
<input name="button" type="button" value="查看cookie" onclick="alert(document.cookie);">
</td>
</tr>
</table>

</form>
</body>
</html>
你的代码错的错误不是一点,我给你改了一些,但有些函数你没有对其调用,我不知道你用哪个去调用,没法给你改了,写代码一定要小心,你这样的代码我还是第一次见,最好是你写一段在调试,然后在写,不要一次写,完在调试
2010-12-06 09:57
流浪天边
Rank: 2
等 级:论坛游民
帖 子:100
专家分:53
注 册:2010-7-12
收藏
得分:0 
谢谢你啊!你的经验我会记住!
2010-12-07 06:10
快速回复:用cookie实现记住内容?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016171 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved