简体   繁体   English

javascript 使用 col 和 row 获取表格上的输入复选框

[英]javascript getting input checkbox on table using col and row

I want to make proses where my data is exist the checkbox will become false , so here is the image that i tried, and using with console.我想在我的数据存在的地方写散文,复选框将变为false ,所以这是我尝试过的图像,并与控制台一起使用。 在此处输入图像描述

I tried to get the column and row to make checkbox become false like here.我试图让列和行使复选框像这里一样变为假。

    let tblModul = document.getElementById('myTable');
    console.log('col :' + col);
    console.log('row :' + row);
    const [intersections, difference, falsecheked] = datarelationships(theemployee, theEmpDatInTable, 'nik', 'NIK');
    appendTheTableEmployee(difference.length, tbody, difference)
    console.log(falsecheked);
    if(falsecheked == false){
        tblModul.rows[row].cells[col].checked = false;
    }

Is there a problem with my code?我的代码有问题吗? because eventough i got the value false, the checkbox didn't unchecked因为即使我得到了错误的值,复选框并没有取消选中

You are using tblModul.rows[row].cells[col].checked = false;您正在使用tblModul.rows[row].cells[col].checked = false; which will try to set checked = false on cell but you need to perform it on input inside that cell .这将尝试在cell上设置checked = false ,但您需要在该cell内的input上执行它。 So you can use like tblModul.rows[row].cells[col].querySelector('input').checked = false;所以你可以像tblModul.rows[row].cells[col].querySelector('input').checked = false; . .

Try it below.在下面试试。

 let tblModul = document.getElementById('myTable'); // in your code use row & col variables I have statically used for testing. tblModul.rows[0].cells[0].querySelector('input').checked = false; tblModul.rows[1].cells[0].querySelector('input').checked = true;
 <table id='myTable'> <tr> <td><input type='checkbox' checked></td> </tr> <tr> <td><input type='checkbox' checked></td> </tr> </table>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM