从同一个表行中查找键上的特定输入值

时间:2012-12-16 09:21:19

标签: jquery jquery-selectors

我有以下表格。我想要做的是当rate[]的值被更改时我希望使用jquery获取更改值的值和product[]的值。

例如:如果我将rate []的值(从表的第一行)更改为100,我想获得rate [] ..100的新值及其product_id [] .. 1001 < / p>

<form id="myform">
  <table>
     <tr>
         <td>Product 1</td>
         <input type="hidden" name="product_id[]" value="1001" />
         <td><input type="text" name="rate[]" value="2" /></td>
         <td><input type="text" name="quantity[]" value="10" /></td>
     </tr>

    <tr>
         <td>Product 2</td>
         <input type="hidden" name="product_id[]" value="1002" />
         <td><input type="text" name="rate[]" value="2" /></td>
         <td><input type="text" name="quantity[]" value="10" /></td>
     </tr>
  <table>
</form>

我的JQuery代码;

<script type="text/javascript">

  $(":text[name='rate[]']").bind("keyup", function() {

     // What to write here?

 });

你能帮我写一下jquery代码来找出这些值吗?

谢谢:)

1 个答案:

答案 0 :(得分:0)

这应该有效:

var productID = $(this).closest('tr').find('input[name^="product_id"]').val();