所以我有以下代码在控制台日志中打印一个数组,它在行中返回期望值,但是当在innerHtml中时,它不会像二维数组那样打印
var matrix = [];
for(var i=0; i<2; i++) {
matrix[i] = [];
for(var j=0; j<2; j++) {
matrix[i][j] = i;
document.getElementById('hassianaJ').innerHTML += '<tr><th scope="row">' +matrix[i][j] + '</th></tr>';
}
}
<!doctype html>
<head>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<head>
<body>
<div class="col-md-12 mt-5">
<table class="table">
<thead id="hassiamaI">
</thead>
<tbody id="hassianaJ">
</tbody>
</table>
</div>
</body>
</head>
答案 0 :(得分:1)
您没有关闭<th>
元素。