P粉7072355682023-09-01 12:48:07
You specified class
for the input, not id
. This means you can't easily tell them apart. However, with some clever JQuery code you can identify the table row where the quantity changed, then get the quantity
and unitprice
and set the totalprice 代码>:
$(document).ready(function() { $('.quantity').keyup(function() { let tableRow = $(this).parent().parent(); let quantity = tableRow.find('.quantity').val(); let unitprice = tableRow.find('.unitprice').val(); let totalprice = quantity * unitprice; tableRow.find('.totalprice').val(totalprice); }) });
So here we get the quantity input $(this)
, and get the parent twice: first
, then
. We store it in tableRow
. Given that we now know the table rows, we can use find() to access the input.
For sample code, please see: https://codepen.io/kikosoft/pen/oNMjqLd一个>