在html中的一个文本框,输入的内容写入cookie里 在html中的一个文本框,输入的内容写入cookie里,然后下次,可以在这个html中能读取上次他往cookie里输入的数据,不知道这个怎么写 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <html><head><title></title><script type="text/javascript">function setCookie(name, value, expires, path, domain, secure) { var curCookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "") if ( (name + "=" + escape(value)).length <= 4000) document.cookie = curCookie else if (confirm("Cookie exceeds 4KB and will be cut!")) document.cookie = curCookie}function getCookie(name) { var prefix = name + "=" var cookieStartIndex = document.cookie.indexOf(prefix) if (cookieStartIndex == -1) return null var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length) if (cookieEndIndex == -1) cookieEndIndex = document.cookie.length return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))}function savecookie(){ var cont=document.getElementById("cook").innerText; if(cont){ setCookie("cont",cont); }}window.onload=function(){ var cont=getCookie("cont"); if(cont) document.getElementById("cook").innerText=cont;}</script></head><body> <div > <input type=area id="te" ><input type=button value="保存进cookie" id=cook onclick=savecookie()> </div></body></html> <script>function aa(o){ document.cookie=o.id+"="+o.value;alert(getvalue())}function getvalue(){ var c=document.cookie.split("; ");//获取cookie for(var i=0;i<c.length;i++){ var arr=c[i].split("="); if("sk4k"==arr[0]){ if(arr.length>1){ return unescape(arr[1]);} else{ return "";} } } return "";}window.onload=function(){ var v=getvalue(); v=(v.length==0)?"":v document.getElementById("sk4k").value=v }</script><input type=text id=sk4k name=sk4k onpropertychange="aa(this)" oninput="aa(this)"> function aa(o){ document.cookie=o.id+"="+o.value;alert(getvalue())} 修改了下,加入可以保存的时间,见注释行<html><head><title></title><script type="text/javascript">function setCookie(name, value, expires, path, domain, secure) { var curCookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "") if ( (name + "=" + escape(value)).length <= 4000){ document.cookie = curCookie } else if (confirm("Cookie exceeds 4KB and will be cut!")) document.cookie = curCookie}function getCookie(name) { var prefix = name + "=" var cookieStartIndex = document.cookie.indexOf(prefix) if (cookieStartIndex == -1) return null var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length) if (cookieEndIndex == -1) cookieEndIndex = document.cookie.length return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))}function savecookie(){ var cont=document.getElementById("te").value; if(cont){ var data=new Date(); data.setTime(data.getTime() + 1*24*3600*1000*1000); //对应天,小时,秒,自己换算设置 setCookie("cont",cont,data); }}window.onload=function(){ var cont=getCookie("cont"); if(cont) document.getElementById("te").value=cont;}</script></head><body> <div > <input type=area id="te" ><input type=button value="保存进cookie" id=cook onclick=savecookie() /> </div></body></html> 就是操作cookie啊!网上多的是,楼主查一查吧 window.onload=function(){ var cont=getCookie("cont"); if(cont) document.getElementById("te").value=cont;}"然后下次,可以在这个html中能读取上次他往cookie里输入的数据"这不是你的要求么打开就行了 图片切换的JS,有时候出现图片乱跳 extJs的ajax返回的js脚本怎么执行啊? 过客达人请进,正则表达式问题,百分送上,非常感谢 求助:数量相减问题 请教两个简单的正则表达式,谢谢! 如何在html页面中做成这种菜单?大家能否给点意见? 关于htc的简单问题 用IFrame时能不能实现一个Frame调用另一个Frame中的函数? 我每次登陆以后怎么看不到我,,,, 小弟求两个js正则表达式,一个是内网ip,一个是外网ip 求教html里面script的type和language属性的作用. js 访问 xml
<title></title>
<script type="text/javascript">
function setCookie(name, value, expires, path, domain, secure) {
var curCookie = name + "=" + escape(value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "")
if ( (name + "=" + escape(value)).length <= 4000)
document.cookie = curCookie
else
if (confirm("Cookie exceeds 4KB and will be cut!"))
document.cookie = curCookie
}
function getCookie(name) {
var prefix = name + "="
var cookieStartIndex = document.cookie.indexOf(prefix)
if (cookieStartIndex == -1)
return null
var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)
if (cookieEndIndex == -1)
cookieEndIndex = document.cookie.length
return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))
}
function savecookie(){
var cont=document.getElementById("cook").innerText;
if(cont){
setCookie("cont",cont);
}
}
window.onload=function(){
var cont=getCookie("cont");
if(cont) document.getElementById("cook").innerText=cont;
}
</script>
</head>
<body> <div >
<input type=area id="te" ><input type=button value="保存进cookie" id=cook onclick=savecookie()>
</div></body>
</html>
<script>
function aa(o){
document.cookie=o.id+"="+o.value;
alert(getvalue())
}
function getvalue(){
var c=document.cookie.split("; ");//获取cookie
for(var i=0;i<c.length;i++){
var arr=c[i].split("=");
if("sk4k"==arr[0]){
if(arr.length>1){ return unescape(arr[1]);}
else{ return "";}
}
}
return "";
}window.onload=function(){
var v=getvalue();
v=(v.length==0)?"":v
document.getElementById("sk4k").value=v
}
</script><input type=text id=sk4k name=sk4k onpropertychange="aa(this)" oninput="aa(this)">
document.cookie=o.id+"="+o.value;
alert(getvalue())}
<html><head>
<title></title>
<script type="text/javascript">
function setCookie(name, value, expires, path, domain, secure) {
var curCookie = name + "=" + escape(value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "")
if ( (name + "=" + escape(value)).length <= 4000){
document.cookie = curCookie
}
else
if (confirm("Cookie exceeds 4KB and will be cut!"))
document.cookie = curCookie
}
function getCookie(name) {
var prefix = name + "="
var cookieStartIndex = document.cookie.indexOf(prefix)
if (cookieStartIndex == -1)
return null
var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)
if (cookieEndIndex == -1)
cookieEndIndex = document.cookie.length
return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))
}
function savecookie(){
var cont=document.getElementById("te").value;
if(cont){
var data=new Date();
data.setTime(data.getTime() + 1*24*3600*1000*1000); //对应天,小时,秒,自己换算设置
setCookie("cont",cont,data);
}
}
window.onload=function(){
var cont=getCookie("cont");
if(cont) document.getElementById("te").value=cont;
}
</script>
</head>
<body> <div >
<input type=area id="te" ><input type=button value="保存进cookie" id=cook onclick=savecookie() />
</div></body>
</html>
var cont=getCookie("cont");
if(cont) document.getElementById("te").value=cont;
}
"然后下次,可以在这个html中能读取上次他往cookie里输入的数据"这不是你的要求么打开就行了