以下是使用 JavaScript 制作奇数偶数表的示例代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>奇数偶数表</title>
</head>
<body>
<table id="numberTable" border="1">
<tr>
<th>数字</th>
<th>奇偶性</th>
</tr>
</table>
<script>
// 定义要生成的数字范围
const start = 1;
const end = 20;
const table = document.getElementById('numberTable');
for (let i = start; i <= end; i++) {
const row = table.insertRow();
const cell1 = row.insertCell(0);
const cell2 = row.insertCell(1);
cell1.innerHTML = i;
if (i % 2 === 0) {
cell2.innerHTML = '偶数';
} else {
cell2.innerHTML = '奇数';
}
}
</script>
</body>
</html>
在上述代码中:
应用场景:
领取专属 10元无门槛券
手把手带您无忧上云