2010-07-17 188 views
0

我試圖只改變的值當前字段後面的下一個選擇框。只選擇下一個選擇框(jQuery)

該表格是一長串具有相同類的字段的行。在「第1行」中「數量」字段的焦點上,我想將「類型」選擇框更改爲同一行中的「框」。我嘗試的所有代碼都會使整個頁面上的所有「類型」選擇框發生更改。我只想要最接近數量字段的最直接的一個。

UOM字段是我嘗試在用戶關注數量時更改的字段。

謝謝!

<tr class="draggable odd"> 
<td class="content-multigroup-cell-field-part-num"> 
    <div id="edit-group-order-0-field-part-num-value-wrapper" class="form-item"> 
     <label for="edit-group-order-0-field-part-num-value">J&amp;B No.: 
     </label> 
     <input type="text" class="form-text text idleField" value="" size="10" id="edit-group-order-0-field-part-num-value" name="group_order[0][field_part_num][value]" pattern="[0-9]*"> 
    </div> 
</td> 
<td class="content-multigroup-cell-field-quantity"> 
    <div id="edit-group-order-0-field-quantity-value-wrapper" class="form-item"> 
     <label for="edit-group-order-0-field-quantity-value">Quantity: 
     </label> 
     <input type="text" class="form-text text idleField" value="" size="5" id="edit-group-order-0-field-quantity-value" name="group_order[0][field_quantity][value]" pattern="[0-9]*"> 
    </div> 
</td> 
<td class="content-multigroup-cell-field-quantity-type"> 
    <div id="edit-group-order-0-field-quantity-type-value-wrapper" class="form-item"> 
     <label for="edit-group-order-0-field-quantity-type-value">UOM: 
     </label> 
     <select id="edit-group-order-0-field-quantity-type-value" class="form-select" name="group_order[0][field_quantity_type][value]"> 
      <option selected="selected" value="">- None - 
      </option> 
      <option value="Box(es)">Box(es) 
      </option> 
      <option value="Case(s)">Case(s) 
      </option> 
      <option value="Each">Each 
      </option> 
      <option value="Feet">Feet 
      </option> 
     </select> 
    </div> 
</td> 

Ĵ&乙編號: 數量: UOM: - 無 - 盒(ES) 情況下() 每個 腳

+0

你能發表你正在使用的代碼/標記嗎? – 2010-07-17 18:17:42

+0

這將有助於查看實際的html以查看DOM層次結構。 – 2010-07-17 18:29:56

+0

我已經用代碼更新了原文。對於那個很抱歉! – Ryan 2010-07-17 19:48:03

回答

0

我假設你正在使用表格標記,並在一個td內的元素的焦點事件。

$('input.quantity').focus(function() { 
    //get current cell, find nearest select.type in the following siblings 
    $(this).parent() 
      .nextAll() 
      .find('select.type:first').val('boxes'); 

}); 
+0

我通過添加另一個「父()」得到了這個工作!謝謝! – Ryan 2010-07-17 19:49:16

0

你試過closest

+0

是的,但我不確定我是否正確地做了。 – Ryan 2010-07-17 19:48:46

相關問題