-3

您好在网上找了一段时间,非常感谢您的帮助。我需要知道在页面重新加载后,哪些涉及 cookie 的脚本可以将以下代码中的切换 div 保持在“CLICKED”状态。感谢所有人和任何人的帮助,并提前表示感谢。

<!DOCTYPE html>
<html>
<head>
  <style>
      p.one { position:relative; width:400px; height:90px; }
      div.two { position:relative; width:400px; height:65px; 
        font-size:36px; text-align:center; 
        color:yellow; background:red;
        padding-top:25px; 
        top:0; left:0; display:none; }
        span.three { display:none; }
      </style>
  <script src="http://code.jquery.com/jquery-latest.js"></script>


</head>
<body>
  <p class="one">
        Let it be known that the party of the first part
        and the party of the second part are henceforth
        and hereto directed to assess the allegations
        for factual correctness... 



 <input type="button" id="toggle_button" value="TEST" />


</div>
        <div id="two" class="two"><span id=''three' class="three">Click here to continue...</span></div>

      </p>
<script>
        $('#toggle_button').click(function () {
          $("#two").fadeIn(3000, function () {
            $("#three").fadeIn(100);
          });
          return false;
        }); 

      </script>

      </body>
      </html>

我怎样才能得到像下面这样的东西来处理我的代码?

 <script type="text/javascript">

    $(function() {

        var cookie = document.cookie,
            state  = cookie.substr(cookie.search('buttonCollapsed=')+16,1),
            elem   = $('div.collapsable');

        if (state == 1) {
            elem.hide();
        }

        elem.slideToogle(function() {

            if ( elem.is(':visible') ) {
                document.cookie = "toggle_button=0";
            } else {
                document.cookie = "toggle_button=1";
            }

        });

    });
    </script>
4

1 回答 1

0

您可以在这里看到如何在 jQuery 中使用 cookie,抱歉 jQuery 网站的 cookie 页面现在没有响应。

你应该做什么在每个点击事件上设置cookie;

$.cookie("lastOne", this.id);

并在文档就绪功能上检查 cookie 是否存在并打开给定的 id;

$(document).ready(function () {
      if ($.cookie("lastOne") != null)
          $("#" + $.cookie("lastOne")).click();
});

这应该够了吧。

于 2012-11-15T16:35:18.840 回答