jquery怎么获取我点击的这个input 获取到包括这个input的tr!求大神!

南明北月 2015-12-23 03:12:55
点击合计的时候 计算这一行的费用总数


这样常规计算没有问题 但是我添加完第二行的时候 我再去修改第一行 然后 第一行的合计 就会根据第二行的数值来合计

这是计算的代码 如果把那个last去掉 他会计算所有的input

页面代码

<table class="js_table" style="width: 98%">
<thead>
<tr>
<th style="width:12%;">日期</th>
<th style="width:15%;">出差起止点</th>
<th style="width:8%;">出差天数</th>
<th style="width:8%;">差旅补贴费</th>
<th style="width:8%;">飞机或火车费</th>
<th style="width:6%;">住宿费</th>
<th style="width:6%;">餐饮费</th>
<th style="width:6%;">交通费</th>
<th style="width:6%;">票据张数</th>
<th style="width:8%;">其他</th>
<th style="width:10%;">合计</th>
<th style="width:10%;">操作</th>
</tr>
</thead>
<script>

</script>
<tbody>
<tr>
<td><input type="text" name="traveldate" class="textbox Wdate" style="width:90%;" placeholder="报销日期" datatype="*" onclick="WdatePicker({});" /></td>
<td><input type="text" name="travelstart" class="textbox" style="width:40%;" datatype="*" />~<input type="text" id="bao2" name="travelend" class="textbox" style="width:40%;" datatype="*" /></td>
<td><input type="text" name="daynumber" class="textbox" style="width:80%;" datatype="money" /></td>
<td><input type="text" id="ss" name="subsidy" class="textbox" style="width:80%;" datatype="money" /></td>
<td><input type="text" id="ss" name="transportationcos" class="textbox" style="width:80%;" datatype="money" /></td>
<td><input type="text" id="ss" name="accommodation" class="textbox" style="width:80%;" datatype="money" /></td>
<td><input type="text" id="ss" name="diningexpen" class="textbox" style="width:80%;" datatype="money" /></td>
<td><input type="text" id="ss" name="traffic" class="textbox" style="width:80%;" datatype="money" /></td>
<td><input type="text" id="ss" name="billnumber" class="textbox" style="width:80%;" datatype="money" /></td>
<td><input type="text" id="ss" name="other" class="textbox" style="width:80%;" datatype="money" /></td>
<td><input type="text" id="btnSum" onblur="count($(this));" name="tradetsum" readonly="true" class="textbox" style="width:80%;" datatype="money" /></td>
<td><a href="javascript:void(0);" class="col_blue row_del"><i class="icon_del"></i> 删除</a></td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="11"><a href="javascript:void(0);" class="col_blue row_add"><i class="icon_edit"></i> 新增一行</a></td>
</tr>
</tfoot>
</table>

新增一行代码

/*表格添加/删除*/
$(".row_del").click(function () {
if ($(".js_table > tbody > tr").length >= 2) {
$(this).parent("td").parent("tr").remove();
}
})
$(".row_add").click(function () {
var new_row = $(".js_table > tbody > tr:eq(0)").clone(true);
$(".js_table > tbody").append(new_row);
$(".js_table > tbody > tr:last > td > input").val("");
})
})


合计计算代码

$(function() {
function summary() {
var s = 0;
$('.js_table > tbody > tr:last > td > input[id="ss"]').each(function() {
var money=isNaN(parseFloat($(this).val()));
if(money){
money=0
}else{
var money=parseFloat($(this).val());
}
s = s + money;
});
return s;
}
$('#btnSum').click(function() {
var _sum = summary();
$(this).val(_sum);
})
})
...全文
1821 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
z1iang 2016-09-14
  • 打赏
  • 举报
回复
sorry,我在写论坛代码,得找找感觉。。。
z1iang 2016-09-14
  • 打赏
  • 举报
回复
我随便回复的
南明北月 2015-12-23
  • 打赏
  • 举报
回复
引用 3 楼 u011376884 的回复:
[quote=引用 2 楼 qq_27246087 的回复:] [quote=引用 1 楼 u011376884 的回复:] 去找上次给你解决的人 他写的代码让他负责
我晕。我再问一个问题。var obj=$(this).parent("td").parent("tr"); 我获取到的这个obj对象 怎么才能获取到对象中的input呢?[/quote] var obj=$(this).parent("td").parent("tr").find("input");[/quote] 终于把坑填好了!最后还是你
  • 打赏
  • 举报
回复
引用 2 楼 qq_27246087 的回复:
[quote=引用 1 楼 u011376884 的回复:] 去找上次给你解决的人 他写的代码让他负责
我晕。我再问一个问题。var obj=$(this).parent("td").parent("tr"); 我获取到的这个obj对象 怎么才能获取到对象中的input呢?[/quote] var obj=$(this).parent("td").parent("tr").find("input");
南明北月 2015-12-23
  • 打赏
  • 举报
回复
引用 1 楼 u011376884 的回复:
去找上次给你解决的人 他写的代码让他负责
我晕。我再问一个问题。var obj=$(this).parent("td").parent("tr"); 我获取到的这个obj对象 怎么才能获取到对象中的input呢?
  • 打赏
  • 举报
回复
去找上次给你解决的人 他写的代码让他负责

87,907

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧