对此感到困惑......所以我有一个按钮,点击后会显示一个隐藏的 div。我试图设置一个cookie onlick,以便即使在页面重新加载后div也会显示,但我没有运气......
我不明白的是如何获得点击状态的值......
例如:
setCookie('CookieName', 'What goes here for the clicked button state value?', 'LENGTH OF COOKIE LIFE')
<html>
<head>
<script type="text/javascript" language="JavaScript">
function SetCookie() {
if(arguments.length < 2) { return; }
var n = arguments[0];
var v = arguments[1];
var d = 0;
if(arguments.length > 2) { d = parseInt(arguments[2]); }
var exp = '';
if(d > 0) {
    var now = new Date();
    then = now.getTime() + (d * 24 * 60 * 60 * 1000);
    now.setTime(then);
    exp = '; expires=' + now.toGMTString();
    }
document.cookie = n + "=" + escape(String(v)) + '; path=/' + exp;
} // function SetCookie()
function ReadCookie(n) {
var cookiecontent = new String();
if(document.cookie.length > 0) {
    var cookiename = n+ '=';
    var cookiebegin = document.cookie.indexOf(cookiename);
    var cookieend = 0;
    if(cookiebegin > -1) {
        cookiebegin += cookiename.length;
        cookieend = document.cookie.indexOf(";",cookiebegin);
        if(cookieend < cookiebegin) { cookieend = document.cookie.length; }
        cookiecontent = document.cookie.substring(cookiebegin,cookieend);
        }
    }
return unescape(cookiecontent);
} // function ReadCookie()
// —>
</script>
<style type="text/css">
#sub3 {
position: absolute;
left: 100px;
top: 200px;
background-color: #f1f1f1;
width: 180px;
padding: 10px;
color: black;
border: #0000cc 2px dashed;
display: none;
}
</style>
<script language="JavaScript">
function setVisibility(id, visibility) {
document.getElementById(id).style.display = visibility;
}
</script>
</head>
<body >
<script language="JavaScript">
function clicked() {
    setVisibility(id, visibility);
    setCookie() // this calls your set cookie function
    return true;
}
</script>
<input id="input1" type=button value='Show Layer' onclick="clicked();">
<div id="sub3">Message Box</div>
</body>
</html>