2013-03-20 104 views
0

我有一個表,看起來像這樣如何獲取每個選定行的下拉列表值?

<table id="grid" class="table table-bordered table-hover table-inline"> 
    <thead> 
     <tr> 
      <th>Id</th> 
      <th>Dropdown List</th> 
      <th><input id="selectAll" type="checkbox" /></th> 
     </tr> 
    </thead> 
    <tbody data-bind="foreach: stuff 
     <tr> 
      <td data-bind="text: someId"></td> 
      <td> 
       <select class="input-medium" data-bind="options: someStuff, optionsText:'DisplayName', optionsValue:'StandardCode'"></select>       
      </td> 
      <td> 
       <input type="checkbox" data-bind="value: someId"/> 
      </td> 
     </tr> 
    </tbody> 
</table> 

,然後即時通訊我的javascript我經過選擇的行迭代這樣

$('grid input[type="checkbox"]:checked').each(function() { 

    var someSelectedId= $(this).val(); 

    var dropDownlistValue= ??  
}); 

我使用擊倒我的數據綁定到表並下降。

當我遍歷行時​​,我如何獲得每行的下拉列表中的選定值,因爲我正在遍歷它們?對於我的生活,我似乎無法弄清楚。謝謝!

回答

2

用途:

var dropDownlistValue = $(this).parent().prev().find('select.input-medium').val(); 
+1

工作就像一個魅力!謝謝! – 2013-03-20 14:34:32

2

或者......

$(this).closest("tr").find("select.input-medium").val(); 

AV的方法可能更快,但要到TR允許更多的靈活性,因爲它會發現選擇不管它在哪裏。

相關問題