Document.createProcessingInstruction() - Web API 接口参考 编辑
createProcessingInstruction()
创建一个新的处理指令节点,并返回。
Syntax
Processing instruction node = document.createProcessingInstruction(target, data)
Parameters
Processing Instruction node
是ProcessingInstruction
节点.target
是指处理指令节点的target部分 (i.e., <?target ... ?>data
是一个字符串,包含了将要添加到节点内的数据。
异常
NOT_SUPPORTED_ERR
- Thrown if you attempt to create a processing instruction node on an HTML document in Gecko 9 (Firefox 9.0 / Thunderbird 9.0 / SeaMonkey 2.6) or earlier. In Gecko 10.0 (Firefox 10.0 / Thunderbird 10.0 / SeaMonkey 2.7) and later, you can use this method on HTML documents.
DOM_INVALID_CHARACTER
- Thrown if you try to add an invalid processing instruction target (it should be an XML name besides any case combination of the letters "xml") or if the closing processing instruction sequence ("?>") is added as part of the data, so unescaped user-provided data cannot be safely used without escaping or otherwise dealing with such situations.
实例
var docu = new DOMParser().parseFromString('<xml></xml>', "application/xml") var pi = docu.createProcessingInstruction('xml-stylesheet', 'href="mycss.css" type="text/css"'); docu.insertBefore(pi, docu.firstChild); alert(new XMLSerializer().serializeToString(docu)); // 弹出框内容: <?xml-stylesheet href="mycss.css" type="text/css"?><xml/>
规范
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论