¿Cómo se puede agregar una casilla de verificación en la entrada de enter?
<html> <head> </head> <body> Search: <input onkeyup="myFunction()" type="search" id="mySearch" value=""> <p>Click the button to display the value of the value attribute of the search field.</p> <p id="demo"></p> <table id="table"> <tr> <td></td> </tr> </table> <script> function myFunction() { if(event.keyCode === 13){ debugger; var table = document.getElementById("table"); var row = table.insertRow(-1); var date = row.insertCell(0); table.appendChild(row); date.innerHTML = document.getElementById("mySearch").value; //insert checkbox// function editTd() { var rows = document.getElementById('table').rows; for (var i = 0; i < rows.length; i++) { var row = rows[i]; for(var j =0; j<row.cells.length; j++){ var inputs = document.createElement("input"); inputs.type = "checkbox"; rows.cells[j].appendChild(inputs); }; }; }; editTd(); } } </script> </body> </html>solo necesita modificar la línea a esto:
rows[i].cells[j].appendChild(inputs);o posiblemente
rows[0].cells[j].appendChild(inputs); <html> <head> </head> <body> Search: <input onkeyup="myFunction()" type="search" id="mySearch" value=""> <p>Click the button to display the value of the value attribute of the search field.</p> <p id="demo"></p> <table id="table"> <tr> <td></td> </tr> </table> <script> function myFunction() { if (event.keyCode === 13) { debugger; var table = document.getElementById("table"); var row = table.insertRow(-1); var date = row.insertCell(0); table.appendChild(row); date.innerHTML = document.getElementById("mySearch").value; //insert checkbox// function editTd() { var rows = document.getElementById('table').rows; for (var i = 0; i < rows.length; i++) { var row = rows[i]; for (var j = 0; j < row.cells.length; j++) { var inputs = document.createElement("input"); inputs.type = "checkbox"; rows[i].cells[j].appendChild(inputs); }; }; }; editTd(); } } </script> </body> </html>muestra 2 casillas de verificación, por lo que si eso no es lo que quería, solo necesita cambiar la lógica de bucle. espero que esto ayude