选中复选框时获取表行的ID [英] Getting the id of a table row when a checkbox is checked
本文介绍了选中复选框时获取表行的ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在表格行中有一个复选框
I have a checkbox inside a table row
<tr id="1">
<td><input type="checkbox" /></td>
<td>lorem</td>
<td>ipsum</td>
<td>css</td>
</tr>
我想在选中复选框时获取ID
I want to get the id when the checkbox is checked
我已经尝试过了
var closestTr = $(':checkbox:checked').closest('tr').attr('id');
alert(closestTr);
我也尝试过 http://jsfiddle.net/AbfJk/3/
为什么没有ID?
推荐答案
尝试一下
$("#thechecked").click(function(){
var closestTr = $(':checkbox:checked').closest('tr').attr('id');
alert(closestTr);
});
工作小提琴: http://jsfiddle.net/AbfJk/7/
无论如何,您的小提琴缺少jquery,并且也缺少)"(您将"end comment"放在错误的行中)
anyway, your fiddle is missing jquery and has also a ")" missing (you put the "end comment" in the wrong line)
这篇关于选中复选框时获取表行的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文