我是JavaScript和它的事件新手。这是我的表格的HTML代码,我有一个收入标题和它的各自的价格。Javascript:在关键事件输入计算它们的总和
<table class="table table-hover table-bordered" id="incomeId">
<thead>
<tr>
<th> sn </th>
<th> Title of income </th>
<th> Price </th>
<th> Action </th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>
<select name="name" id="inputID" class="form-control">
<option value=""> -- Select One --</option>
</select>
</td>
<td>
<input type="text" name="name" id="income_price" class="form-control income" value="" title="" required="required">
</td>
<td>
<span class="glyphicon glyphicon-trash"></span>
</td>
</tr>
</tbody>
<tfoot>
<tr>
<td></td>
<td></td>
<td> Total: <div class="total" id="total"></div> </td>
<td></td>
</tr>
</tfoot>
</table>
<button type="button" class="btn btn-info" id="add-new">Add New Income</button>
于表JavaScript代码添加新行,
$('#add-new').on('click', function() {
$("#incomeId").each(function() {
var tds = '<tr>';
jQuery.each($('tbody tr:last td', this), function() {
tds += '<td>' + $(this).html() + '</td>';
});
tds += '</tr>';
if ($('tbody', this).length > 0) {
$('tbody', this).append(tds);
} else {
$(this).append(tds);
}
});
});
但我想从一个总段的所有价格段,并和每一个价格表创建新行之前。当我创建新行时,最近创建的价格应该添加到前一个总价中。 请帮我找出解决方案。
请问你的问题涉及到在标题中多KEYUP? –
我想使用keyup事件从每个输入框中获取值并将其添加到总节中。 –