加载时关闭树切换

tree-toggle to be closed on load

我不知道 js,但偶尔会用到它,如果问题很简单,我很抱歉,但我尝试了不同的东西,但它们对我不起作用。

所以我有一棵树,我有这个脚本可以实际工作并在单击时隐藏显示树枝。

但是默认情况下树是打开的。如何在第一次加载时强制关闭树?

     <!-- 

 - HIDE DISPLAY TREE BRANCH WHEN CLICKED ON HEAD ITEM -->
            <script>
                   $(document).ready(fu

nction () {
                    $('label.tree-toggler').click(function () {
                $(this).parent().children('ul.tree').toggle(300);
                    });
                  });
         </script>

这是我的来源html

                        <ul class="nav nav-list tree">




                                         <li><div>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;
                                           S: # 2  Men Fashion (<i> <a href="/item/subcategory/subcategory_details/2"> Details </a> - <a href="/item/itemgroup/new/2/http://127.0.0.1:8000/item/category/list/%3Fid=2&name=&keywords=&author=&creation_time=/">Add Itemgroup</a> -
                                          <a href="/item/subcategory/edit/2/http://127.0.0.1:8000/item/category/list/%3Fid=2&name=&keywords=&author=&creation_time=/">Edit</a> -
                                          <a href="/item/subcategory/delete/2/http://127.0.0.1:8000/item/category/list/%3Fid=2&name=&keywords=&author=&creation_time=/">Delete</a></i>)</div>
                                               <ul class="nav nav-list tree">




                                                             <li><div><i>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;
                                                               I: # 21  ffdsfdsf </i>(<i><a href="/item/itemgroup/itemgroup_details/21">Details </a>-
                                                              <a href="/item/itemgroup/edit/21/http://127.0.0.1:8000/item/category/list/%3Fid=2&name=&keywords=&author=&creation_time=/">Edit</a> -
                                                              <a href="/item/itemgroup/delete/21/http://127.0.0.1:8000/item/category/list/%3Fid=2&name=&keywords=&author=&creation_time=/">Delete</a></i>)</div>



                                                             </li>




                                                             <li><div><i>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;
                                                               I: # 22  saddascsa </i>(<i><a href="/item/itemgroup/itemgroup_details/22">Details </a>-
                                                              <a href="/item/itemgroup/edit/22/http://127.0.0.1:8000/item/category/list/%3Fid=2&name=&keywords=&author=&creation_time=/">Edit</a> -
                                                              <a href="/item/itemgroup/delete/22/http://127.0.0.1:8000/item/category/list/%3Fid=2&name=&keywords=&author=&creation_time=/">Delete</a></i>)</div>



                                                             </li>




                                                  </ul>



                                 </li>

使用<ul class="nav nav-list tree" style="display:none;">。 Wat jquery toggle does, is set display to either none (hidden) or block (visible.)

您可以使用 css 添加 display:none 到您的 ul

喜欢<ul class="nav nav-list tree" style="display:none">

或在页面加载时调用 jquery $(this).parent().children('ul.tree').css('display', 'none');