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

View in English Always switch to English

DocumentType:name 属性

基线 广泛可用

自 2015年7月 起,此特性已在主流浏览器中得到支持,可在大多数设备和浏览器版本中正常使用。

DocumentType 的只读属性 name 返回文档的类型。

对于合成的 DocumentType,此属性将反映 DOMImplementation.createDocumentType() 参数中给出的值。

对于 HTML 文档,无论源代码中的实际 doctype 是什么,浏览器始终将其设置为 html

字符串。

示例

js
const docType = document.implementation.createDocumentType("html", "", "");

console.log(docType.name); // 显示“html”

规范

规范
DOM
# dom-documenttype-name

浏览器兼容性