求一段很简单的js代码!!!
展开全部
function getCookieVal(offset) {
var endstr = document.cookie.indexOf (";", offset);
if(endstr == -1) {
endstr = document.cookie.length;
}
return unescape(document.cookie.substring(offset, endstr));
}
function getCookie(name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
var j = 0;
while(i < clen) {
j = i + alen;
if(document.cookie.substring(i, j) == arg)
return getCookieVal(j);
i = document.cookie.indexOf(" ", i) + 1;
if(i == 0)
break;
}
return null;
}
function deleteCookie(name) {
var exp = new Date();
var cval = getCookie(name);
exp.setTime(exp.getTime() - 1);
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
var gCookieExpDays = 80;
function setCookie(name, value) {
var argv = setCookie.arguments;
var argc = setCookie.arguments.length;
var exp = (argc > 2) ? argv[2] : gCookieExpDays;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
var expires = new Date();
deleteCookie(name);
expires.setTime(expires.getTime() + (exp*24*60*60*1000));
document.cookie = name + "=" + value +
"; expires=" + expires.toGMTString() +
((domain == null) ? "" : ("; domain=" + domain)) +
((path == null) ? "" : ("; path=" + path)) +
((secure == true) ? "; secure" : "");
}
-----------------------------------------
上边是设置cookie的方法,一般用到的也就上边几种
下边是如下代码
setCookie("load","1");
window.onload = fuction(){
if(getCookie("load")!=1){
document.location.reload();
}
}
把我写的代码放到页面里即可。。。
更多的可以hi我
var endstr = document.cookie.indexOf (";", offset);
if(endstr == -1) {
endstr = document.cookie.length;
}
return unescape(document.cookie.substring(offset, endstr));
}
function getCookie(name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
var j = 0;
while(i < clen) {
j = i + alen;
if(document.cookie.substring(i, j) == arg)
return getCookieVal(j);
i = document.cookie.indexOf(" ", i) + 1;
if(i == 0)
break;
}
return null;
}
function deleteCookie(name) {
var exp = new Date();
var cval = getCookie(name);
exp.setTime(exp.getTime() - 1);
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
var gCookieExpDays = 80;
function setCookie(name, value) {
var argv = setCookie.arguments;
var argc = setCookie.arguments.length;
var exp = (argc > 2) ? argv[2] : gCookieExpDays;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
var expires = new Date();
deleteCookie(name);
expires.setTime(expires.getTime() + (exp*24*60*60*1000));
document.cookie = name + "=" + value +
"; expires=" + expires.toGMTString() +
((domain == null) ? "" : ("; domain=" + domain)) +
((path == null) ? "" : ("; path=" + path)) +
((secure == true) ? "; secure" : "");
}
-----------------------------------------
上边是设置cookie的方法,一般用到的也就上边几种
下边是如下代码
setCookie("load","1");
window.onload = fuction(){
if(getCookie("load")!=1){
document.location.reload();
}
}
把我写的代码放到页面里即可。。。
更多的可以hi我
展开全部
网页加载完后 刷新
window.onload = fuction(){
document.location.reload()
}
出发 on_click()函数 刷新
function on_click(){
document.location.reload()
}
直接html 超链接 刷新
<a href="#" onClick="document.location.reload()">刷新</a>
window.onload = fuction(){
document.location.reload()
}
出发 on_click()函数 刷新
function on_click(){
document.location.reload()
}
直接html 超链接 刷新
<a href="#" onClick="document.location.reload()">刷新</a>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询