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

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
doctype

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support