當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


HTML DOM Keygen用法及代碼示例

HTML DOM keygen 對象用於表示 <keygen> 元素。 <keygen> 元素將使用 HTML DOM document.createElement() 方法創建並由 getElementById() 訪問。它是 HTML5 中的新函數。

用法:

document.getElementById("ID">);

屬性值

  • 自動對焦用於設置或返回頁麵加載時keygen元素是否獲得焦點。
  • challenge:它用於設置或返回 keygen 元素的挑戰屬性的值。
  • 殘障人士它用於設置或返回 keygen 元素是否被禁用。
  • 形式:It 返回包含 keygen 元素的表單的引用。
  • key 類型:用於設置或返回 keygen 元素的 keytype 屬性的值。
  • 名稱: 它用於設置或返回 keygen 元素的 name 屬性的值。
  • 類型: 它返回 keygen 字段的表單元素類型。

範例1:以下示例演示了訪問 <keygen> 元素。



HTML


<!DOCTYPE html>
<html>
   
<head>
    <style>
        h1 {
            color:green;
        }
        h2 {
            font-family:Impact;
        }
        body {
            text-align:center;
        }
    </style>
</head>
<body>
    <h1>GeeksforGeeks</h1>
     
    <h2>HTML DOM Keygen Object</h2>
    <br>
     
    <form id="myGeeks">
        Username:<input type="text" name="uname">
        <br><br> Encryption:
        <keygen id="Geeks" form="myGeeks"
                name="secure" autofocus>
        <input type="submit">
    </form>
     
<p>
        To find out whether the keygen element
        automatically gets focus on page load or
        not, click the "Check" button.
    </p>
    <button onclick="My_focus()">Check</button>
     
    <p id="test"></p>
    <script>
        function My_focus() {
            var d = document.getElementById("Geeks").autofocus;
            document.getElementById("test").innerHTML = d;
        }
    </script>
</body>
</html>

輸出:

創建一個注冊機對象:

document.createElement()

範例2:

HTML


<!DOCTYPE html>
<html>
<head>
    <style>
        h1 {
            color:green;
        }
        h2 {
            font-family:Impact;
        }
        body {
            text-align:center;
        }
    </style>
</head>
<body>
    <h1>GeeksforGeeks</h1>
    <h2>HTML DOM Keygen Object</h2>
    <br>
     
    <form id="myGeeks">
        Username:<input type="text" name="uname">
        <br><br> Encryption:
        <input type="submit">
    </form>
     
<p>
        Click on the below "create" button
        to create a Keygen Element.
    </p>
    <button onclick="create()">Create</button>
     
    <p id="test"></p>
     
    <script>
        function create() {
            var x = document.createElement("KEYGEN");
            x.setAttribute("name", "security");
            document.body.appendChild(x);
            alert("A kEYGEN element is created");
        }
    </script>
</body>
</html>

輸出:

支持的瀏覽器:

  • 穀歌瀏覽器
  • Opera
  • 不支持 Internet Explorer
  • Firefox
  • 蘋果Safari



相關用法


注:本文由純淨天空篩選整理自ManasChhabra2大神的英文原創作品 HTML DOM Keygen Object。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。