2016-04-26 67 views
0

我想獲得input.salePrice的輸入值。下面是HTML:從jQuery中的父級獲取td的輸入值

<tr role="row" id="0"> 
    <td class="v-align-middle semi-bold">TEST</td> 
    <td class="v-align-middle text-right quantityModule"> 
     <div class="input-group"> 
      <span class="input-group-addon primary"><a href="#" class="quantityMinus"><i class="fa fa-minus-circle"></i></a></span> 
      <input type="text" class="form-control text-center quantity" data-v-min="0" data-v-max="999" data-w-empty="zero" value="1" autocomplete="off" style="width:50px;"> 
      <span class="input-group-addon primary"><a href="#" class="quantityPlus"><i class="fa fa-plus-circle"></i></a></span> 
     </div> 
    </td> 
    <td class="v-align-middle text-right priceModule"> 
     <div class="input-group"><input type="text" class="form-control text-right salePrice" value="24.00" autocomplete="off" style="width:80px;"><span class="input-group-addon primary">%</span></div></td><td class="v-align-middle text-right">24.00 
    </td> 
</tr> 

我開始喜歡這個不對勁:

$('#orderTable tbody').on('click', 'a.quantityPlus', function() { 
    var salePrice = $(this).parents('tr input.salePrice').val(); 
}); 

任何想法?

回答

1

好吧,這真的很簡單,這裏是代碼:

$('#orderTable tbody').on('click', 'a.quantityPlus', function() { 
    var tr = $(this).parents('tr').find('input.salePrice').val(); 
});