在变量中传递切换打开状态

Passing toggle open state in variable

本文关键字:状态 变量      更新时间:2023-09-26

我有一个切换开关打开/关闭 DIV,其中包含 UL 列表,如下所示:

<div id="dropdown-1">
        <div class="option-heading">
                    <i class="fa fa-angle-double-up"></i>
                    <i class="fa fa-angle-double-down"></i>
                    <h5>Title</h5>      
        </div>
        <div class="option-content">
        <ul class="check_list check_list_show">
             <li><a href="#>Item 1</a><li/>
             <li><a href="#>Item 2</a><li/>
             <li><a href="#>Item 3</a><li/>
        </ul>
        </div>
</div>   

JS代码是:

<script>
        $(document).ready(function() {
            $(".option-content").hide();
            $(".fa-angle-double-up").hide();
            $(".option-heading").click(function(){
                    $(this).next(".option-content").slideToggle(500);
                    $(this).find(".fa-angle-double-up, .fa-angle-double-down").toggle();
            });
        });
</script>

用户从该列表中选择链接后,相同的页面将刷新并在其上显示结果。但是,该 DIV 会自动关闭,我需要它保持打开状态。

我不是JS开发人员,对于刷新后如何通过其打开状态没有任何想法。任何建议将不胜感激!

小提琴:http://jsfiddle.net/bumL495j/

在 url 中传递查询字符串(i. 锚标记) lik

<li><a href="link.html?menutoggle=open">Item 1</a><li/>
 $(document).ready(function() {
            $(".option-content").hide();
            $(".fa-angle-double-up").hide();
             var urlstring = window.location.href; // check for menu toggle you can pass itemid also based on that you can highlight menus
             if(urlstring.indexOf("menutoggle=open")>0){
                  $(this).next(".option-content").slideToggle(500);
                    $(this).find(".fa-angle-double-up, .fa-angle-double-down").toggle();
             }
        });

您需要将此脚本粘贴到该菜单项链接的每个页面中。 我不知道本地存储,但你也可以谷歌搜索它。