ProcessingInstruction: target 属性
ProcessingInstruction 接口的只读 target 属性代表 ProcessingInstruction 所针对的应用程序。
例如
html
<?xml version="1.0"?>
是一个处理指令,其 target 为 xml。
值
一个包含应用程序名称的字符串。
示例
在 XML 文档中
js
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 = `This processing instruction's target is: ${doc.firstChild.target}`;
在 HTML 文档中
处理指令行将被视为并表示为一个 Comment 对象。
html
<?xml version="1.0"?>
<pre></pre>
js
const node = document.querySelector("pre").previousSibling.previousSibling;
const result = `Node with the processing instruction: ${node.nodeName}: ${node.nodeValue}\n`;
document.querySelector("pre").textContent = result;
规范
| 规范 |
|---|
| DOM # dom-processinginstruction-target |
浏览器兼容性
加载中…
另见
- DOM API