HTML DOM 單選按鈕型別屬性


Input Checkbox 型別屬性返回/設定 Input Checkbox 的型別。

語法

以下是語法 −

  • 返回字串值
inputCheckboxObject.type
  • type 設定為字串值
inputCheckboxObject.type = stringValue

字串值

此處,"stringValue" 可以是以下內容 -

stringValue詳情
checkbox它定義輸入型別是複選框
radio它定義輸入型別是單選按鈕
text它定義輸入型別是文字

例項

讓我們看一個 Input Checkbox type 屬性的例項 −

 即時演示

<!DOCTYPE html>
<html>
<head>
<title>Type Attribute of Checkbox</title>
</head>
<body>
<form id="Form">
<div>
Other: <input id="formCheckbox" type="checkbox" name="formCheckbox">
</div>
</form>
<button onclick="changeType()">Change type of input</button>
<div id="displayDiv"></div>
<script>
   var typeOfInput = document.getElementById("formCheckbox");
   var displayDiv = document.getElementById("displayDiv");
   displayDiv.textContent = 'Type of Input: ' + typeOfInput.type function changeType(){
      if(typeOfInput.type == 'checkbox'){
         typeOfInput.type = 'text' displayDiv.textContent = 'Type of Input: ' + typeOfInput.type
      }
   }
</script>
</body>
</html>

輸出

這將產生以下輸出 −

單擊“更改輸入型別”按鈕之前 −

單擊“更改輸入型別”按鈕之後 −

更新於: 30-Jul-2019

86 次檢視

開啟你的 職業生涯

完成課程,獲取證書

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