如何使用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 接亲祝福语简短10字
14 厂庆祝福语大全简短
15 学校校长新年祝福语简短
16 提前生日祝福语 简短
17 节日祝福语大全简短创意
18 部门过年祝福语简短独特