HTML DOM 輸入 URL 型別屬性


HTML DOM 輸入 URL 型別屬性返回/設定輸入 URL 的型別。

語法

採用以下語法:

  • 返回字串值
inputURLObject.type
  • 將型別設定為字串值
inputURLObject.type = stringValue

字串值

此處,“stringValue”可以是以下內容:

stringValue
詳情
email
它定義輸入型別為電子郵件
url
它定義輸入型別為 url
radio
它定義輸入型別為單選按鈕
tel
它定義輸入型別為電話號碼,併為輸入顯示數字鍵盤

示例

讓我們看一個 輸入 URL 型別 屬性的示例:

 線上演示

<!DOCTYPE html>
<html>
<head>
<title>Input URL type</title>
<style>
   form {
      width:70%;
      margin: 0 auto;
      text-align: center;
   }
   * {
      padding: 2px;
      margin:5px;
   }
   input[type="button"] {
      border-radius: 10px;
   }
</style>
</head>
<body>
<form>
<fieldset>
<legend>URL-type</legend>
<label for="URLSelect"></label>
<input type="url" id="URLSelect" >
<input type="button" onclick="getTypeOfInput()" value="What to enter?">
</fieldset>
</form>
<script>
   var labelSelect = document.querySelector("label");
   var inputURL = document.getElementById("URLSelect");
   function getTypeOfInput() {
      labelSelect.innerHTML = inputURL.type.toUpperCase()+': ';
   }
</script>
</body>
</html>

輸出

這將產生以下輸出:

在單擊 “輸入什麼?”按鈕之前:

在單擊 “輸入什麼?”按鈕之後:

更新於: 30-Jul-2019

105 次瀏覽

開啟您的 職業生涯

完成課程以獲得認證

開始
廣告
© . All rights reserved.