返回当前文档关联的文档类型定义(DTD). 返回的对象实现了 DocumentType 接口。使用 DOMImplementation.createDocumentType() 方法可以创建一个DocumentType类型的对象。

语法

doctype = document.doctype;
  • doctype 是一个只读属性.

示例

var doctypeObj = document.doctype;

console.log(
  "doctypeObj.name: "           + doctypeObj.name            + "\n" +
  "doctypeObj.internalSubset: " + doctypeObj.internalSubset  + "\n" +
  "doctypeObj.publicId: "       + doctypeObj.publicId        + "\n" +
  "doctypeObj.systemId: "       + doctypeObj.systemId
);

附注

如果当前文档没有DTD,则该属性返回null

DOM level 2 不支持编辑文档类型定义。

规范

规范 状态 备注
DOM
Document: doctype
Living Standard

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
doctypeChrome Full support 1Edge Full support 12Firefox Full support YesIE ? Opera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android ?

Legend

Full support  
Full support
Compatibility unknown  
Compatibility unknown

文档标签和贡献者

此页面的贡献者: ridiculousjam, mdnwebdocs-bot, teoli, jsx, ziyunfei
最后编辑者: ridiculousjam,