我有这个html代码:
jsfiddle here

<table align="center">
    <td align="center" colspan="5">Table</td>
    <tbody>
        <tr> // Table Headings (Not important, removed)
        </tr>
             // First Row (of many)
        <tr>
            <td>Cell 1</td>              // Cell 1
            <td>Cell 2</td>              // Cell 2

            // This is the cell I want the price in
            <td class="unitprice" align="center">2.99</td> // Cell 3 <-- I want this value

            // Onkeyup of this input box, get the value in cell 3 into a var.
            <td align="center">
            <input type="text" id="qty" name="qty" size="2" value="1" onkeyup="getValues();" onkeypress="return isNumberKey(event);"/>
            </td>

            <td class="totalprice" align="center">TOTAL PRICE</td>
        </tr>
</tbody>
</table>


我正在使用此javascript从“数量”文本框中获取值,

  function getValues(e)
  {
      var qty = e.value; // Get me the value in qty
      // This is what I tried
      //var Something = $(this).parent().find("td.unitprice").html();
      alert(Something); // Does not work
  }


基本上

input [QTY]的Onblur,获取qty的值,获取其旁边的价格,然后仅将其更新为div类(totalprice)。

我有数十条记录,因此此功能应针对更改输入的特定行。

最佳答案

$('input[type="text"]').keyup(function(){
    var _parent = $(this).parent();
    _parent.next().html(Number(_parent.prev().html()) * Number($(this).val()));
});


工作演示:http://jsfiddle.net/AlienWebguy/6x7wn/9/

使用此资源:http://www.texotela.co.uk/code/jquery/numeric/

10-05 20:50
查看更多