HTML DOM TableHeader Object แสดงถึงองค์ประกอบ
สร้างวัตถุ TableHeader
ไวยากรณ์
ต่อไปนี้เป็นไวยากรณ์ -
document.createElement(“TH”);
คุณสมบัติของวัตถุ TableHeader
| ทรัพย์สิน | คำอธิบาย |
|---|---|
| cellIndex | ส่งกลับตำแหน่งของเซลล์ในคอลเลกชั่นเซลล์ของแถวตาราง |
| colSpan | ส่งกลับและแก้ไขค่าแอตทริบิวต์ colspan ของตาราง |
| ส่วนหัว | ส่งกลับและแก้ไขค่าแอตทริบิวต์ส่วนหัวของตาราง |
| ย่อ | ส่งกลับและแก้ไขค่าแอตทริบิวต์ abbr ของตาราง |
| rowSpan | ส่งกลับและแก้ไขค่าแอตทริบิวต์ rowspan ของตาราง |
ให้เราดูตัวอย่างของวัตถุ TableHeader:
ตัวอย่าง
<!DOCTYPE html>
<html>
<style>
body {
color: #000;
background: lightblue;
height: 100vh;
text-align: center;
}
table {
margin: 2rem auto;
width: 400px;
}
.btn {
background: #db133a;
border: none;
height: 2rem;
border-radius: 2px;
width: 40%;
display: block;
color: #fff;
outline: none;
cursor: pointer;
margin: 1rem auto;
}
</style>
<body>
<h1>DOM TableHeader Object Demo</h1>
<table border="2">
<thead>
<tr class="table-header">
</tr>
<thead>
<tbody>
<tr>
<td>John</td>
<td>English</td>
</tr>
<tr>
<td>Elon</td>
<td>Germany</td>
</tr>
</tbody>
</table>
<button onclick="get()" class="btn">Create a TableHeader</button>
<script>
function get() {
var th1 = document.createElement("TH");
var th2 = document.createElement("TH");
th1.innerHTML = "Name";
th2.innerHTML = "Language";
document.querySelector('.table-header').appendChild(th1);
document.querySelector('.table-header').appendChild(th2);
}
</script>
</body>
</html> ผลลัพธ์

คลิกที่ “สร้าง TableHeader ” เพื่อสร้างวัตถุ TableHeader
