2014-05-12 36 views
0

我想只有一个打开的面板(一种手风琴菜单)。我想只有一个打开的面板(一种手风琴菜单)

我试了一下到目前为止(在代码中的注释部分):

//$('#tabs-1').show(100); 
//$('#tabs-2').hide(); 
//$('#tabs-3').hide(); 

如果标签-1选择if ($('#tabs-1').is(":visible"))然后隐藏tabs-2tabs-3将被隐藏,tabs-1将被显示,但如果我触发,之后它不会作出反应,如果我例如点击tabs-2,因为tabs-1仍然打开('#tabs-1').is(":visible")(它被捕获在这个块) 它不能被关闭。我知道,这可不行我改变现有的代码,但我不认为不同的解决方案的...

可能看看如何代码看起来像:

function CloseTabInfo() { 
     $(".BWTabVerticalTitle").on("click", function() { 
      //alert("ausgeführt."); 
      var contentDiv = $(this).attr("data-forcolapse"); 
      $(contentDiv).toggle(900); 
      if ($('#tabs-1').is(":visible")) { 
       //[START] Close other tabs, only one has to be opend 
       //$('#tabs-1').show(100); 
       //$('#tabs-2').hide(); 
       //$('#tabs-3').hide(); 
       //[END] 
       if ($("input:checked").val() == 1) { 
        $('.BWShipmentType').text('@BWHtml.translate("Documents")'); 
       } 
       else if ($("input:checked").val() == 2) { 
        $('.BWShipmentType').text('@BWHtml.translate("Goods")'); 
       } 
       //$('.BWShipmentType').text($("input:checked").val()); 
       $('.BWTabVerticalPreferences').text($('#shippingDetails_preferences').val()); 
      } else if ($('#tabs-2').is(':visible')) { 
       //[START] Close other tabs, only one has to be opend 


       //$('#tabs-1').hide(); 
       //$('#tabs-3').hide(); 
       //$('#tabs-2').show(100); 
       //[END] 
       $('.BWSenderInfo').text($('#senderAddress_SenderAddress option:selected').text()); 
      } 
      else if ($('#tabs-3').is(':visible')) { 
       //[START] Close other tabs, only one has to be opend 

       //$('#tabs-1').hide(); 
       //$('#tabs-2').hide(); 
       //$('#tabs-3').show(100); 
       //[END] 
       $('.BWReceiverInfo').text($('#receiverAddress_matchCode').val()); 
       if ($('#shippingDetails_payment option:selected').text() != "Choose One") { 
        $('.BWPaymentInfo').text($('#shippingDetails_payment option:selected').text()); 
       } 
       $('.BWCostInfo').text($('#shippingDetails_CostList option:selected').text()); 

      } 
      else { 
       //$('.BWShipmentType').text(''); 
       //$('.BWTabVerticalPreferences').text(''); 
       //$('.senderAddressInfo').text(''); 
      } 
     }); 

我这对于jQuery来说是一种新鲜的东西,这让我很难解决这个简单的问题。

+2

你应该用HTML小提琴以及使其更容易让我们来帮助你。 ** [点击这里](http://jsfiddle.net/)** –

回答

1

您正在尝试做什么可以很容易地完成jQuery UI,jQuery的官方扩展,它增加了许多UI元素,如手风琴或选项卡。

这里是你如何可以轻松实现手风琴:

<script> 
    $(function() { 
    $("#accordion").accordion(); 
    }); 
</script> 
<div id="accordion"> 
    <h3>Section 1</h3> 
    <div> 
    <p>Content 1</p> 
    </div> 
    <h3>Section 2</h3> 
    <div> 
    <p>Content 2</p> 
    </div> 
    <h3>Section 3</h3> 
    <div> 
    <p>Content 3</p> 
    </div> 
</div> 
相关问题