Phương thức createTHead () bảng
Thí dụ
Tạo một phần tử <thead> (và chèn một phần tử <tr> và <td> vào nó):
// Find a <table> element with id="myTable":
var table = document.getElementById("myTable");
// Create an empty <thead> element and add it to the table:
var header = table.createTHead();
// Create an empty <tr> element and add it to the first position of <thead>:
var row = header.insertRow(0);
// Insert a new cell (<td>) at the first position of the "new" <tr> element:
var cell = row.insertCell(0);
// Add some bold text in the new cell:
cell.innerHTML = "<b>This is a table header</b>";
Định nghĩa và Cách sử dụng
Phương thức createTHead () tạo một phần tử <thead> trống và thêm nó vào bảng.
Lưu ý: Nếu phần tử <thead> đã tồn tại trên bảng, phương thức createTHead () trả về phần tử hiện có và không tạo phần tử mới.
Lưu ý: Phần tử <thead> phải có một hoặc nhiều thẻ <tr> bên trong.
Mẹo: Để xóa phần tử <thead> khỏi bảng, hãy sử dụng phương thức deleteTHead () .
Hỗ trợ trình duyệt
Method | |||||
---|---|---|---|---|---|
createTHead() | Yes | Yes | Yes | Yes | Yes |
Cú pháp
tableObject.createTHead()
Thông số
Không có |
Chi tiết kỹ thuật
Giá trị trả lại: | Phần tử <thead> mới được tạo (hoặc hiện có) |
---|
Các ví dụ khác
Thí dụ
Tạo và xóa phần tử <thead>:
function myCreateFunction() {
var table = document.getElementById("myTable");
var header = table.createTHead();
var row = header.insertRow(0);
var cell = row.insertCell(0);
cell.innerHTML = "<b>This is a table header</b>";
}
function myDeleteFunction() {
document.getElementById("myTable").deleteTHead();
}
Các trang liên quan
Tham chiếu HTML: thẻ HTML <thead>
❮ Đối tượng bảng