怎么使用原生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>


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM