HTML - DOMTokenList supports() 方法



HTML DOMTokenList **supports()** 方法返回一個布林值,表示引數中指定的標記是否受 DOMTokenList 支援。此方法用於功能檢測。

語法

domtokenlist.supports(token);

引數

此方法接受如下所示的單個引數。

引數 描述
token 它表示要檢查其支援性的標記名稱。

返回值

它返回一個布林值,其中 true 表示支援的標記,false 表示不支援的標記。

HTML DOMTokenList 'supports()' 方法示例

以下示例檢查 iframe 元素是否支援 "allow-popups"。

<!DOCTYPE html>
<html>
<head>
    <title>
        HTML DOMTokenList supports() Method
    </title>
</head>
<body>
    <iframe id="support"></iframe>
    <p>Click below to check.</p>
    <button onclick="fun()">Check</button>
    <p id="token"></p>
    <script>
        function fun() {
            let x = document.getElementById("support")
                .sandbox.supports("allow-popups");
            document.getElementById("token").innerHTML = x;
        }
    </script>
</body>
</html>

支援的瀏覽器

方法 Chrome Edge Firefox Safari Opera
supports() 是 49 是 17 是 49 是 10.1 是 36
html_domtokenlist_reference.htm
廣告