2014-02-18 81 views
0

我有一個下拉菜單,當我選擇「安排」時,其他下拉菜單需要可見。 當您再次選擇其他字段時,第二個下拉列表需要「重置/不選」。在下拉菜單中選擇項目需要顯示/隱藏另一個下拉菜單

我該怎麼做?

的HTML:

<table width="300" border="0" cellspacing="0" cellpadding="0"> 
    <tr> 
    <td>Select:</td> 
    <td align="right"> 
    <select name="mydropdown" class="formfield"> 
     <option value="">No selection</option> 
     <option value="Diner">Diner</option> 
     <option value="Lunch">Lunch</option> 
     <option value="Arrangement">Arrangement</option> 
    </select> 
    </td> 
    </tr> 
    <tr> 
    <td height="10"></td> 
    <td> </td> 
    </tr> 
    <tr class="go-hide"> 
    <td>Type arrangement</td> 
    <td align="right"> 
    <select class="formfield"> 
     <option value="">No selection</option> 
     <option value="All you can eat Tapas">All you can eat Tapas</option> 
     <option value="High Tea">High Tea</option> 
     <option value="Combinaties">Combinations</option> 
    </select> 
    </td> 
    </tr> 
</table> 

這裏舉例: http://jsfiddle.net/fourroses666/R555U/1/

回答

0

我認爲你正在尋找的答案已經張貼在這裏:

Show/Hide <select> dropdown, with jQuery, based on value

在樂這是用jQuery來做到這一點的一種方法。

+0

謝謝!我想我會提出另一個關於「不選擇」的問題,但這基本上是我想要做的! – fourr

+0

我會的,但首先我喜歡有1件事排序。如果你看這裏:http://jsfiddle.net/fourroses666/stAAm/515/當選擇安排2,然後選擇組合安排需要被取消/重置。 – fourr

+0

因爲當我發送表單時,我會看到選擇排列2和組合3 3 – fourr

0

這工作:

$(document).ready(function(){ 

    $('#keuze').change(function() { 
     if ($('#keuze option:selected').text() == "Arrangement"){ 
      $('.go-hide').hide(); 
      $('#arrangement').show(); 
      $('#combinatie option:eq(0)').attr('selected','selected'); 
     } else if ($('#keuze option:selected').text() == "Combinatie"){ 
      $('.go-hide').hide(); 
      $('#combinatie').show(); 
      $('#arrangement option:eq(0)').attr('selected','selected'); 
     } else { 
      $('.go-hide').hide(); 
      $('#arrangement option:eq(0)').attr('selected','selected'); 
      $('#combinatie option:eq(0)').attr('selected','selected'); 
     } }); 

}); 
相關問題