HTML DOM 文字輸入型別屬性


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

語法

以下是語法 −

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

字串值

這裡,“字串值”可以包括以下內容 −

字串值詳細資訊
email定義輸入型別為電子郵件
text定義輸入型別為文字
radio定義輸入型別為單選按鈕
tel定義輸入型別為電話號碼,並顯示數字鍵盤輸入

示例

我們來看一下文字輸入型別屬性的示例 −

 線上演示

<!DOCTYPE html>
<html>
<head>
<title>Input Text 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>Text-type</legend>
<label for="TextSelect"></label>
<input type="text" id="TextSelect" >
<input type="button" onclick="getTypeOfInput()" value="What to enter?">
</fieldset>
</form>
<script>
   var labelSelect = document.querySelector("label");
   var inputText = document.getElementById("TextSelect");
   function getTypeOfInput() {
      labelSelect.innerHTML = ' Plain '+inputText.type+': ';
   }
</script>
</body>
</html>

輸出

將產生以下輸出 −

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

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

更新於: 30-Jul-2019

117 次瀏覽

開啟職業生涯

完成課程獲得認證

立即開始
廣告
© . All rights reserved.