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