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
廣告