คุณสมบัติ Input Checkbox type จะคืนค่า/sets ของ Input Checkbox
ไวยากรณ์
ต่อไปนี้เป็นไวยากรณ์ -
- คืนค่าสตริง
inputCheckboxObject.type
- การตั้งค่า ประเภท เป็นค่าสตริง
inputCheckboxObject.type = stringValue
ค่าสตริง
ที่นี่ “stringValue” สามารถเป็นดังต่อไปนี้ -
| stringValue | รายละเอียด |
|---|---|
| ช่องทำเครื่องหมาย | กำหนดประเภทอินพุตคือช่องทำเครื่องหมาย |
| วิทยุ | กำหนดประเภทอินพุตเป็นวิทยุ |
| ข้อความ | กำหนดประเภทอินพุตที่เป็นข้อความ |
ตัวอย่าง
ให้เราดูตัวอย่างของ ประเภทช่องทำเครื่องหมายอินพุต ทรัพย์สิน −
<!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> ผลลัพธ์
สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ -
ก่อนคลิกปุ่ม 'เปลี่ยนประเภทการป้อนข้อมูล' -

หลังจากคลิกปุ่ม 'เปลี่ยนประเภทการป้อนข้อมูล' -
