DOMImplementation.createDocumentType()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

DOMImplementation.createDocumentType() 方法返回一个 DocumentType 对象,它可以在文档创建时用在 DOMImplementation.createDocument ,或者通过Node.insertBefore()Node.replaceChild() 等方法放在文档中。

语法

var doctype = document.implementation.createDocumentType(qualifiedNameStr, publicId, systemId);

参数

qualifiedNameStr

DOMString 类型的值,包含一个合规的名称,如 svg:svg

publicId

DOMString 类型的值,包含 PUBLIC 标识符。

systemId

DOMString 类型的值,包含 SYSTEM 标识符。

示例

js
var dt = document.implementation.createDocumentType(
  "svg:svg",
  "-//W3C//DTD SVG 1.1//EN",
  "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd",
);
var d = document.implementation.createDocument(
  "http://www.w3.org/2000/svg",
  "svg:svg",
  dt,
);
alert(d.doctype.publicId); // -//W3C//DTD SVG 1.1//EN

规范

Specification
DOM Standard
# ref-for-dom-domimplementation-createdocumenttype①

浏览器兼容性

BCD tables only load in the browser

参见