如何使用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 送给学长毕业祝福语简短