-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を使用する方法については、 jQueryWebサイトの申し訳ありませんがCookieページが現在応答していません。

あなたがすべきことは、クリックイベントごとにCookieを設定することです。

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

ドキュメント準備機能で、Cookieが存在するかどうかを確認し、指定されたIDを開きます。

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

それでうまくいくはずです。

于 2012-11-15T16:35:18.840 に答える