HTML - DOM 文档 doctype 属性



doctype 属性返回与当前 HTML 文档关联的 DTD(文档类型声明)。这是一个只读属性。它返回 DocumentType 对象作为 doctype 名称,如果未为给定文档指定 DTD,则返回 null。

语法

document.doctype;

返回值

它返回 DocumentType 对象作为 doctype。

HTML DOM 文档 'doctype' 属性示例

以下示例给出 HTML 文档的 doctype。

<!DOCTYPE html>
<html lang="en">
<head>
    <title>
        HTML DOM document doctype Property
    </title>
</head>
<body>
    <h3>
        HTML DOM document doctype Property
    </h3>
    <button onclick="fun()">Get doctype</button>
    <p>The doctype for this HTML document is:</p>
    <p id="type"></p>
    <script>
        function fun() {
            let x = document.doctype.name;
            document.getElementById("type").innerHTML = x;
        }
    </script>
</body>
</html>

支持的浏览器

属性 Chrome Edge Firefox Safari Opera
doctype 是 1 是 12 是 1 是 1 是 12.1
html_dom_document_reference.htm
广告
© . All rights reserved.