HTML DOM Document importNode ()
Thí dụ
Nhập phần tử <h1> đầu tiên từ iframe (tài liệu khác):
const frame = document.getElementsById("myFrame");
const h1 = frame.contentWindow.document.getElementsByTagName("H1")[0];
const node = document.importNode(h1, true);
Định nghĩa và Cách sử dụng
Phương importNode()
thức nhập một nút từ một tài liệu khác.
Khi tham số thứ hai được đặt thành true
, các nút con cũng sẽ được nhập.
Ghi chú
Nút đã nhập không bị xóa khỏi tài liệu gốc.
Nút được nhập là một bản sao của bản gốc.
Xem thêm:
Cú pháp
document.importNode(node, deep)
Thông số
Parameter | Description |
node | Required. A node from another document. Can be type of node. |
deep | Required.false : only the node itself is imported.true : child nodes (descendants) are also imported. |
Giá trị trả lại
Loại | Sự miêu tả |
Nút | Nút đã nhập. |
Hỗ trợ trình duyệt
document.importNode()
là một tính năng DOM Mức 2 (2001).
Nó được hỗ trợ đầy đủ trong tất cả các trình duyệt:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | 9-11 | Yes | Yes | Yes | Yes |