怎么使用原生js往表格table里插数据

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>table</title>
</head>
<body>

<button onclick="addRow(Math.round(Math.random()*10000),(Math.random()*10).toFixed(1))">add row</button>

<table id="tb" border="1px">
<thead>
<tr>
<td>sum</td>
<td>rate</td>
</tr>
</thead>
</table>

<script>
var tb = document.getElementById("tb");

function addRow(col1, col2) {
var row = tb.insertRow(tb.FetchRowCount);
row.insertCell(0).innerHTML = col1;
row.insertCell(1).innerHTML = col2;
}

addRow('1000', '0.5');
addRow('8000', '0.6');
</script>
</body>
</html>
原文地址:https://www.cnblogs.com/parasis/p/10172788.html