javascript - 加载时关闭树切换

标签 javascript jquery tree

我不懂 js,但偶尔会使用它,如果问题很琐碎,很抱歉,但我尝试了不同的东西,但它们对我不起作用。

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

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

     <!-- 

 - 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>

最佳答案

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

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

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

关于javascript - 加载时关闭树切换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36943601/

相关文章:

javascript - 无法接收 Google Hangout 按钮的回调

javascript - 使用 jQuery 将 XML 加载到 JS 变量中,无需 JS 警报

javascript - 排序 jQuery 函数,仅在最后一个完成时运行

jQuery悬停效果问题

haskell - 在 Haskell 中根据父关系长出一棵树

javascript - React Native "run-ios"意外的 token

javascript - Chrome 中的窗口 onload 事件失败

javascript - Angular JS : Insert one directive into another directive dynamically

javascript - 使用 tree-model-js 将树转换回 JSON

tree - 如何解读sklearn决策树tree_中的children_left属性