简体   繁体   中英

how to add checkbox in javascript append table column

i'm trying to inject HTML inside javascript code for creating html table. now i can append the table but i can't create checkbox inside the first table column. if you have any idea about this tell me pls...

i'm trying many HTML code for checkbox but i can't solve the problem.

$("#tbody1").html('<tr>'+
    '<td><input type="checkbox" name="alerted"</td>'+
'</tr>')

i need to set checkbox in append table column.

你还没有关闭你的标签..<input type="checkbox" name="alerted"<... , >在“alerted”之后丢失

You are missing to close input tage inside javascript code . Try this

$("#tbody1").html('<tr>'+
                      '<td><input type="checkbox" name="alerted"></td>'+
                  '</tr>')

Using javascript, you can create an element and append.

 let bd = document.getElementById('bd'); for(let i=1; i<=10; i++) { let tr = document.createElement('tr'); let td = document.createElement('td'); td.innerHTML = i; tr.appendChild(td); bd.appendChild(tr); }
 <table> <tr> <th>Name</th> </tr> <tbody id="bd"> </tbody> </table>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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