2016-04-29 38 views
0

我不知道js,但偶爾也要使用它,所以如果問題不重要,那麼很抱歉,但是我會嘗試不同的東西,但它們不適合我。tree-toggle在加載時關閉

所以我有一棵樹,我有這個腳本,實際上工作和隱藏顯示單擊樹枝時。

但是,默認情況下該樹已打開。如何強制樹在第一次加載時關閉?

 <!-- 

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

回答

1

您可以使用CSS添加display:none你UL

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

或撥打一個jQuery當頁面已加載$(this).parent().children('ul.tree').css('display', 'none');

1

使用<ul class="nav nav-list tree" style="display:none;">。屈jQuery的切換呢,設置顯示要麼無(隱藏)或塊(可見)