[英]How to set dynamic id to a table and append it to a div?
我想使用 class table_container 在 div 容器中动态创建 10 个表和 append。 这是我正在尝试的片段,我是否需要根据我的要求对其进行任何更改?
for( let i =0; i< 10; i++){ var table = document.createElement('table'); table.setAttribute("id", "table"+i); }
<div class="table_container"> </div>
// Get a reference to the container.
const container = document.querySelectorAll('.table_container')[0];
for(let i = 0; i < 10; i++){
// Create the new <table>
const table = document.createElement('table');
table.setAttribute("id", "table"+i);
// Append it to the inside of the container.
container.appendChild(table);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.