document.adoptNode & document.importNode & node.ownerDocument All In One


document.adoptNode & document.importNode & node.ownerDocument All In One

外部文档节点插入当前文档之前,你必须使用 document.importNode() 从外部文档导入源节点,或者使用 document.adoptNode() 导入源节点

document.adoptNode


https://developer.mozilla.org/en-US/docs/Web/API/Document/adoptNode

document.importNode

importNode(externalNode)
importNode(externalNode, deep)


https://developer.mozilla.org/en-US/docs/Web/API/Document/importNode

node.ownerDocument

如果在本身是文档的节点上使用此属性,则值为 null

// Given a node "div", get the top-level HTML child of the document object

const div = document.querySelector('div');

const documentRoot = div.ownerDocument;
// #document
const html = documentRoot.documentElement;
// <html>...</html>

// document self object ❓iframe

const dom = document.querySelector('html');

const documentRoot = dom.ownerDocument;
// <html>...</html> ✅
// null ❌
// document self object

document;
// #document
document.ownerDocument;
// null ✅

document.adoptNode & document.importNode & node.ownerDocument All In One

https://developer.mozilla.org/en-US/docs/Web/API/Node/ownerDocument

https://developer.mozilla.org/en-US/docs/Web/API/Node

https://developer.mozilla.org/en-US/docs/DOM/document

refs

https://github.com/mdn/content/pull/18005



Flag Counter


©xgqfrms 2012-2020

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载

原创文章,作者:506227337,如若转载,请注明出处:https://blog.ytso.com/272096.html

(0)
上一篇 2022年7月8日
下一篇 2022年7月8日

相关推荐

发表回复

登录后才能评论