javascript - 突出显示和禁用第一个和第二个表中的行,所选数据相同
问题描述
有两个表example1和example2,以及复选框>>如果检查第一个表中的一行并选择第二个表中的一行。并点击“匹配记录”按钮。如果两条线相等,则需要用颜色突出显示该行并禁用复选框。我尝试过并卡住了,请建议解决方案,有时第一个表行匹配第二个表的多行。
$('#example').DataTable({
'columnDefs': [{
'targets': 0,
'searchable': false,
'orderable': false,
'className': 'dt-body-center',
'render': function(data, type, full, meta) {
return '<input type="checkbox" name="id[]" value="' + $('<div/>').text(data).html() + '">';
}
}],
'order': [
[1, 'asc']
]
});
$('#example1').DataTable({
'columnDefs': [{
'targets': 0,
'searchable': false,
'orderable': false,
'className': 'dt-body-center',
'render': function(data, type, full, meta) {
return '<input type="checkbox" name="id[]" value="' + $('<div/>').text(data).html() + '">';
}
}],
'order': [
[1, 'asc']
]
});
var table = $('#example').DataTable();
$('#example tbody').on('click', 'tr', function() {
alert(table.row(this).data());
});
var table2 = $('#example1').DataTable();
$('#example1 tbody').on('click', 'tr', function() {
alert(table2.row(this).data());
});
$("#matchedRecords").on('click', function() {
$('#example tbody tr').each(function() {
var row = $(this).text();
var isChecked = $(this).find("input:checkbox").is(":checked");
$('#example1 tbody tr').each(function() {
var _t = $(this);
if (row == _t.text() && isChecked) {
_t.prop({
'disabled': true,
background: red
});
}
});
});
});
解决方案
我已经改变了你的matchedRecords
功能,所以它看起来像这样:
$("#matchedRecords").on('click', function() {
$('#example tbody input:checked').each(function() {
var inx = $(this).closest("tr").index();
if($('#example1 tbody tr:eq('+inx+') input').is(":checked")){
$('#example1 tbody tr:eq('+inx+') input').prop({'disabled':true})
$('#example1 tbody tr:eq('+inx+')').css("background-color","red")
$(this).prop({'disabled':true})
$(this).closest('tr').css("background-color","red")
}
})
});
推荐阅读
- java - 如何在java中设置公共静态最终类实例的值
- azure - 使用 Azure devops REST API 获取 github 存储库
- spring-boot - Spring Security + Keycloak 授权:如何将端点与资源相关联?
- python - 'LinearRegression' 对象没有属性 'save'
- c# - WPF在itemscontrol中画布上的元素之间绘制线条
- c++ - 使用枚举类初始化结构成员时编译错误
- html - 我可以摆脱 Flexdashboards 中的顶部栏吗?
- transformation - 将正态分布转换为偏态正态分布
- python - 如何在 Python 中将 DataFrame 列转换为行?
- c - 在 Linux 中使用 mmap 访问物理地址空间:将正确的参数传递给 mmap