此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

Document:doctype 属性

Baseline Widely available

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

Document 接口的 doctype 只读属性表示与当前文档关联的文档类型声明(DTD)DocumentType 对象。

DocumentType 对象。

示例

js
const doctypeObj = document.doctype;

console.log(`doctypeObj.name: ${doctypeObj.name}`);
console.log(`doctypeObj.internalSubset: ${doctypeObj.internalSubset}`);
console.log(`doctypeObj.publicId: ${doctypeObj.publicId}`);
console.log(`doctypeObj.systemId: ${doctypeObj.systemId}`);

备注

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

DOM 第 2 级规范不支持编辑文档类型声明。

规范

Specification
DOM
# ref-for-dom-document-doctype①

浏览器兼容性