简体   繁体   English

jQuery / Grails-在文本框更改时检测表中的行

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

I need to recalculate a field A after changing a field B. 更改字段B后,我需要重新计算字段A。

But they are in a row ia table with "n" number of rows (foreach). 但是它们在表的行中,行数为“ n”(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等创建变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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