2012-06-18 118 views
1

這是我的HTML代碼默認後點擊子菜單顯示隱藏使用jQuery的子菜單,隱藏

<ul class="list"> 
    <li class="pagenav"> 
    <a title="Government" href="#">Government</a> 
     <ul> 
      <li class="page_item page-item-14"><a href="#">Code of Ordinances</a></li> 
      <li class="page_item page-item-5267"><a href="#">Finance</a> 
       <ul class="children"> 
        <li class="page_item page-item-16"><a href="#">Fiscal Year</a></li> 
        <li class="page_item page-item-5280"><a href="#">Comprehensive</a></li> 
       </ul> 
      </li> 
      <li class="page_item page-item-5267"><a href="#">Finance year</a> 
       <ul class="children"> 
        <li class="page_item page-item-16"><a href="#">Year</a></li> 
        <li class="page_item page-item-5280"><a href="#">Comprehensive year</a></li> 
       </ul> 
      </li> 
     </ul> 
    </li> 
</ul> 

默認顯示這樣的

Government 

Code of Ordinances 

Finance 

Finance year 

後點擊財經節目like that

Government 

Code of Ordinances 

Finance 

Fiscal Year 

Comprehensive 

Finance year 

i意思是說,我想用默認值,然後單擊財政與金融一年時間子菜單顯示&隱藏

回答

1
$('.page_item .children').hide(0); 

$('.page_item').click(function(){ 
    if($('.children').hasClass('vis')){ 
    $('.children', this).removeClass('vis'); 
    $('.children', this).hide();  
    }else{ 
    $('.children', this).addClass('vis'); 
    $('.children', this).show(); 
    } 
}); 
+0

謝謝,該代碼爲我工作 –

0
<style> 
    li.pageitem ul.children { 
    display:none; 
} 
</style> 

<script> 
$('li.pageitem').click(function(){ 
    $(this).find('ul.children').toggle(); 
}); 
</script> 
+0

感謝答覆後隱瞞財政與金融年度的子菜單,但這些代碼是不工作 –