![]() |
#2
jianghong_022010-12-06 09:57
<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> 你的代码错的错误不是一点,我给你改了一些,但有些函数你没有对其调用,我不知道你用哪个去调用,没法给你改了,写代码一定要小心,你这样的代码我还是第一次见,最好是你写一段在调试,然后在写,不要一次写,完在调试 |

<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>
我是菜鸟一个,对于调试程序很差劲,希望大家能帮我看看这个程序那里出错?<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>
如图:
只有本站会员才能查看附件,请 登录
问题:提交和重填按钮没反应?