动态添加行问题 我想做一个程序,可以动态添加/删除表格的行,输入数字后可以自动运算求和,添加个求和按钮也行啊,请高人指点,谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 参照http://www.cnblogs.com/fooo/archive/2009/05/18/1459631.html同时加入事件onchange<input type="text" onchange=''/>再调用方法处理合计函数。 使用jQuery最为简单<table id="table1"> <thead> <tr> <th>成人</th> <th>老人</th> <th>儿童</th> </tr> </thead> <tbody> <tr> <td class="adult"><input type="text" onkeyup="sum('Adult')" /></td> <td class="oldman"><input type="text" onkeyup="sum('Oldman')" /></td> <td class="children"><input type="text" onkeyup="sum('Children')" /></td> <td> <a href="#" onclick="return createRow()">添加</a> | <a href="#" onclick="return deleteRow(this)">删除</a> </td> </tr> </tbody> <tfoot> <tr> <td><input id="sumAdult" type="text"</td> <td><input id="sumOldman" type="text" /></td> <td><input id="sumChildren" type="text" /></td> <td>合计</td> </tr> </tfoot> </table> function createRow() { $('#table1 tbody tr:first').clone(true).appendTo($('#table1 tbody')).find('input[type=text]').val(''); return false; } function deleteRow(elem) { if ($('#table1 tbody tr').length > 1) $(elem).parents('tr').remove(); sum('Adult'); sum('Oldman'); sum('Children'); return false; } function sum(sumType) { var total = 0; $('#table1 tbody .' + sumType.toLowerCase() + ' input').each(function() { total += isNaN(parseInt($(this).val())) ? 0 : parseInt($(this).val()); }); $('#sum' + sumType).val(total); } 菜鸟问题 回复“引用”功能? window.onload 是不是也等iframe窗口的内容也载入完毕才 执行事件? jquery中dialog的问题 如何判断一个网页里的两个表单?如何不冲突 加段 关键字跳转的jsp 自己就是写不好,谁能帮帮忙? 哪个朋友给小弟发个梅花雪2.0的树,不胜感激!~ javascript做的浮动 div工具条 ie打印问题 div滚动条不支持鼠标中键? 如何在当页面打开时,图片的大小自动填满屏幕??? document.getElementById 的一个问题 关于js的数组取值的问题!急!急!急!
<input type="text" onchange=''/>再调用方法处理合计函数。
<table id="table1">
<thead>
<tr>
<th>成人</th>
<th>老人</th>
<th>儿童</th>
</tr>
</thead>
<tbody>
<tr>
<td class="adult"><input type="text" onkeyup="sum('Adult')" /></td>
<td class="oldman"><input type="text" onkeyup="sum('Oldman')" /></td>
<td class="children"><input type="text" onkeyup="sum('Children')" /></td>
<td>
<a href="#" onclick="return createRow()">添加</a> |
<a href="#" onclick="return deleteRow(this)">删除</a>
</td>
</tr>
</tbody>
<tfoot>
<tr>
<td><input id="sumAdult" type="text"</td>
<td><input id="sumOldman" type="text" /></td>
<td><input id="sumChildren" type="text" /></td>
<td>合计</td>
</tr>
</tfoot>
</table> function createRow() {
$('#table1 tbody tr:first').clone(true).appendTo($('#table1 tbody')).find('input[type=text]').val('');
return false;
} function deleteRow(elem) {
if ($('#table1 tbody tr').length > 1) $(elem).parents('tr').remove();
sum('Adult');
sum('Oldman');
sum('Children');
return false;
} function sum(sumType) {
var total = 0;
$('#table1 tbody .' + sumType.toLowerCase() + ' input').each(function() {
total += isNaN(parseInt($(this).val())) ? 0 : parseInt($(this).val());
});
$('#sum' + sumType).val(total);
}