Nhập tài liệu HTML DOMNode()
Ví 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);
Hãy tự mình thử »Sự miêu tả
Phương thức importNode()
nhập một nút từ một tài liệu khác.
Với 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à bản sao của nút 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ả về
Kiểu | Sự miêu tả |
Nút | Nút đã nhập. |
Hỗ trợ trình duyệt
document.importNode()
là tính năng DOM Cấp 2 (2001).
Nó được hỗ trợ đầy đủ trong tất cả các trình duyệt:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | 9-11 |