1 第一个html输入的第一个数据作为第二个html生成表格的行数2 第二个html生成表格的四个列名依次为MaxAllocationNeedTime3 第一个html输入的第二个数据作为第二个html生成表格的每一列内的列数4 根据我给的两个html代码写出对应的js代码
由于没有提供具体的HTML代码,以下是假设的HTML代码:
第一个HTML:
<!DOCTYPE html>
<html>
<head>
<title>Page 1</title>
<script src="script.js"></script>
</head>
<body>
<label for="rows">Enter number of rows:</label>
<input type="number" id="rows" name="rows">
<label for="cols">Enter number of columns:</label>
<input type="number" id="cols" name="cols">
<button onclick="generateTable()">Generate Table</button>
</body>
</html>
第二个HTML:
<!DOCTYPE html>
<html>
<head>
<title>Page 2</title>
</head>
<body>
<table id="myTable">
<thead>
<tr>
<th>Max</th>
<th>Allocation</th>
<th>Need</th>
<th>Time</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<script src="script.js"></script>
</body>
</html>
对应的JS代码:
function generateTable() {
var rows = document.getElementById("rows").value;
var cols = document.getElementById("cols").value;
var table = document.getElementById("myTable").getElementsByTagName('tbody')[0];
for (var i = 0; i < rows; i++) {
var tr = document.createElement('tr');
for (var j = 0; j < cols; j++) {
var td = document.createElement('td');
tr.appendChild(td);
}
table.appendChild(tr);
}
}
原文地址: https://www.cveoy.top/t/topic/brhz 著作权归作者所有。请勿转载和采集!