树形切换在负载时关闭

时间:2016-04-29 16:46:19

标签: javascript jquery tree

我不认识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>

2 个答案:

答案 0 :(得分:1)

使用<ul class="nav nav-list tree" style="display:none;">。 Wat jquery toggle确实将显示设置为none(隐藏)或block(可见。)

答案 1 :(得分:1)

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

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

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