通过带有虚线参数的 JavaScript 添加 table 标签

Adding a table tag via JavaScript with a dashed parameter

我正在尝试使用 Javascript 添加 Bootstrap Table table 标签。 table 标签的参数之一是 data-pagination。由于 -,这种添加它的方法失败了。

我该如何解决这个问题?

期望的输出:

<table id="mytable" data-pagination="true" class="table table-striped"></table>

我的代码:

var table_div = document.createElement('table');
table_div.id = 'mytable';
table_div.className = "table table-striped";
table_div.data-pagination = "true";
document.body.appendChild(table_div);

table_div.setAttribute('data-pagination', 'true')

在这种情况下,您可以使用 dataset,例如:

table_div.dataset.pagination = true;

希望对您有所帮助。

var table_div = document.createElement('table');
table_div.id = 'mytable';
table_div.className = "table table-striped";
table_div.dataset.pagination = "true";
document.body.appendChild(table_div);

console.log(document.body.innerHTML)