我想让用户能够选择表格中的复选框,然后显示下一个表格单元格行数据。
我创建了一个测试项目
http://jsfiddle.net/tonymaloney1971/8n4c42ap/
因此,在我的示例中,如果您选择第 1 行上的复选框,我想要一个显示项目 1 的警报框。
$("input[type='checkbox']").change(function (e) {
if ($(this).is(":checked")) {
$(this).closest('tr').addClass("highlight_row");
//this errors?
var itemID = $('.record_table', this).html();
alert(itemID);
} else {
$(this).closest('tr').removeClass("highlight_row");
}
});
谢谢
最佳答案
您可以查看Demo
下面是更新后的JS代码
$(document).ready(function () {
$('.record_table tr').click(function (event) {
if (event.target.type !== 'checkbox') {
$(':checkbox', this).trigger('click');
}
});
$("input[type='checkbox']").change(function (e) {
if ($(this).is(":checked")) {
$(this).closest('tr').addClass("highlight_row");
//this errors?
var itemID = $(this).parent('td').next('td').html();
alert(itemID);
} else {
$(this).closest('tr').removeClass("highlight_row");
}
});
});
我想这会对你有帮助
关于javascript - JQuery获取checkbox和html的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25267498/