เอกสาร HTML DOM importNode()
ตัวอย่าง
นำเข้าองค์ประกอบ <h1> แรกจาก iframe (เอกสารอื่น):
const frame = document.getElementsById("myFrame");
const h1 = frame.contentWindow.document.getElementsByTagName("H1")[0];
const node = document.importNode(h1, true);
ความหมายและการใช้งาน
วิธีimportNode()
การนำเข้าโหนดจากเอกสารอื่น
พารามิเตอร์ที่สองที่ตั้งค่าเป็นtrue
โหนดย่อยจะถูกนำเข้าด้วย
บันทึก
โหนดที่นำเข้าจะไม่ถูกลบออกจากเอกสารต้นฉบับ
โหนดที่นำเข้าเป็นสำเนาของต้นฉบับ
ดูสิ่งนี้ด้วย:
ไวยากรณ์
document.importNode(node, deep)
พารามิเตอร์
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. |
คืนมูลค่า
พิมพ์ | คำอธิบาย |
โหนด | โหนดที่นำเข้า |
รองรับเบราว์เซอร์
document.importNode()
เป็นคุณลักษณะ DOM ระดับ 2 (2001)
ได้รับการสนับสนุนอย่างเต็มที่ในเบราว์เซอร์ทั้งหมด:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | 9-11 | Yes | Yes | Yes | Yes |