我试图找出onclick事件的下一个复选框是否已选中。如果选中了下一个复选框,则我希望背景色为白色。图片1显示黄色背景为未选中的行,白色背景为已选中的行。图2显示了当我检查黄色行时,下一行变为黄色,如果已经选中,我希望它保持白色。
我可以使用下一个功能吗?这是我到目前为止的代码:
$('input[id="chkRow"]').on('change', (function () {
if (this.checked) {
$(this).closest('tr').css("background-color", "white");
$(this).closest('tr').next('tr').css("background-color", "yellow");
}
else {
$(this).closest('tr').css("background-color", "yellow");
$(this).closest('tr').next('tr').css("background-color", "white");
}
}));
获取当前TD的索引,并使用该索引在下一行中找到相应的单元格,然后检查是否选中了该框。
$('input[id="chkRow"]').on('change', function() {
var curRow = $(this).closest("tr");
var nextRow = curRow.next("tr");
if (this.checked) {
curRow.css("background-color", "white");
var thisColumn = $(this).closest("td").index();
if (nextRow.children("td").eq(thisColumn).find(":checkbox").is(":checked")) {
nextRow.css("background-color", "white");
} else {
nextRow.css("background-color", "yellow");
}
} else {
curRow.css("background-color", "yellow");
nextRow.css("background-color", "white");
}
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句