简体   繁体   中英

jQuery/Grails- Detect Row in a Table when textbox is changing

I need to recalculate a field A after changing a field B.

But they are in a row ia table with "n" number of rows (foreach).

To make the necessary recalculations I have to get the row that the change is made. Here is a example code. Thanks!

  $('#number').keyup(function () { var num=parseFloat($('#number').val()); var price=parseFloat($('#price').val()); var newAmount= num*price; document.getElementById("priceAmount").value = newAmount; }); 
 <table> <thead> <tr> <th> Name <th> <th> Product <th> <th> Price <th> <th> Number <th> <th> Price Amount <th> <tr> </thead> <tbody> <tr> <g:each var="sale" status="i" in="${saleInstanceList}"> <td>${sale.name}"></td> <td>${sale.product}"></td> <td>${sale.price}"></td> <g:hiddenField name="price" value="${sale.price}"/> <td><g:textField name="number" value="${sale.number}"></g:textField></td> <td><g:textField name="priceAmount" value="${sale.priceAmount}"></g:textField></td> </tr> </g:each> </tbody> </table> 

我猜你必须每行做一个jQuery函数,并用row-id等创建变量。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM