如何使用JavaScript布置表格单元格,行和列?
要在JavaScript中正确布局表,请使用tableLayout属性。将属性设置为fixed以设置布局。
示例
您可以尝试运行以下代码来设置使用JavaScript布局表格单元格,行和列的方式-
<!DOCTYPE html>
<html>
<head>
<style>
table, td {
border: 2px solid blue;
}
#myID {
width: 100%;
}
</style>
</head>
<body>
<button onclick = "display()">Set Layout Property</button>
<table id = "myID">
<tr>
<td>This is a text for demo</td>
<td>This is another text</td>
</tr>
<tr>
<td>One</td>
<td>1</td>
</tr>
<tr>
<td>Two</td>
<td>2</td>
</tr>
<tr>
<td>Three</td>
<td>3</td>
</tr>
</table>
<script>
function display() {
document.getElementById("myID").style.tableLayout = "fixed";
}
</script>
</body>
</html>热门推荐
10 圣诞祝福语简短小学
11 祖国七十华诞简短祝福语
12 老师送的祝福语简短
13 生日祝福语大全女生简短
14 祝女性生日祝福语简短
15 牛年女神节祝福语简短
16 情人表白祝福语简短大气
17 老公开业祝福语简短
18 官宣新年祝福语简短