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 July 2015.

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 Standard
# ref-for-dom-document-doctype①

浏览器兼容性

BCD tables only load in the browser