DOM
target 属性是 ProcessingInstruction 接口的一个只读属性,它表示该 ProcessingInstruction 的目标。
例如:
<?xml version="1.0"?>
是一个 target 为 xml 的处理指令。
值
一个包含应用程序名称的字符串。
示例
在 XML 文档中
<output></output>
let parser = new DOMParser();
const doc = parser.parseFromString(
'<?xml version="1.0"?><test/>',
"application/xml",
);
const pi = doc.createProcessingInstruction(
"xml-stylesheet",
'href="mycss.css" type="text/css"',
);
doc.insertBefore(pi, doc.firstChild);
const output = document.querySelector("output");
output.textContent = `这个处理指令的 target 是:${doc.firstChild.target}`;
在 XML 文档中
在 HTML 文档中
在 HTML 文档中,处理指令行将被视为并表示为 Comment 对象。
<?xml version="1.0"?>
<pre></pre>
const node = document.querySelector("pre").previousSibling.previousSibling;
const result = `节点的处理指令:${node.nodeName}: ${node.nodeValue}\n`;
document.querySelector("pre").textContent = result;
在 HTML 文档中
规范
浏览器兼容性
参见
来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。
