如何手动刷新加一 不要自动加一的
发布网友
发布时间:2024-10-03 22:24
我来回答
共1个回答
热心网友
时间:2024-10-11 16:39
html 无法保存状态,可以用cookie
<html>
<head>
<script language="javascript">
var b=0;
function a()
{
var tmp = GetCookie("b");
if( tmp == "" ){
SetCookie("b","0");
tmp = 1;
}
b=tmp*1+1;
SetCookie("b",b);
document.getElementById("div1").innerHTML=b;
//setTimeout("a()",1000);
}
function SetCookie(sName, sValue)
{
document.cookie = sName + "=" + escape(sValue) + "; ";
}
function GetCookie(sName)
{
var aCookie = document.cookie.split("; ");
for (var i=0; i < aCookie.length; i++)
{
var aCrumb = aCookie[i].split("=");
if (sName == aCrumb[0])
return unescape(aCrumb[1]);
}
}
function DelCookie(sName)
{
document.cookie = sName + "=" + escape(sValue) + "; expires=Fri, 31 Dec 1999 23:59:59 GMT;";
}
</script>
</head>
<body onload="a()">
<div id ="div1"></div>
因为html刷新无法保存状态,所以只能借助cookie
<INPUT TYPE="button" value="清空cookie" onclick="javascript:SetCookie('b','1');document.getElementById('div1').innerHTML=1">
</body>
</html>