我有一个jQuery百分比计算器,正在使用.closest('td')
工作.我需要在前面的表格单元格<td>
中显示结果.
$(document).on("change keyup blur live", "input", ".change-calculator", e => {
let $td = $(e.currentTarget).closest('td');
let from = Number($td.find('.calc-from').val());
let to = Number($td.find('.calc-to').val());
let result = ((to - from) / from) * 100;
$td.next().find('.calc-result').text(result.toFixed(2));
$td.next().find('.calc-result').val(result.toFixed(2));
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table id="abcde-table" class="display" style="width:100%">
<thead>
<tr>
<th>Result</th>
<th>Calculator</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<input type="text" class="calc-result">
</td>
<td>
<input type="text" class="change-calculator calc-from" value="1500"><br>
<input type="text" class="change-calculator calc-to" value="">
</td>
</tr>
</tbody>
</table>