簡體   English   中英

javascript 使用 col 和 row 獲取表格上的輸入復選框

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

我想在我的數據存在的地方寫散文,復選框將變為false ,所以這是我嘗試過的圖像,並與控制台一起使用。 在此處輸入圖像描述

我試圖讓列和行使復選框像這里一樣變為假。

    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;
    }

我的代碼有問題嗎? 因為即使我得到了錯誤的值,復選框並沒有取消選中

您正在使用tblModul.rows[row].cells[col].checked = false; 這將嘗試在cell上設置checked = false ,但您需要在該cell內的input上執行它。 所以你可以像tblModul.rows[row].cells[col].querySelector('input').checked = false; .

在下面試試。

 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