คุณสมบัติประเภทการรีเซ็ตอินพุต HTML DOM เชื่อมโยงกับองค์ประกอบอินพุตที่มีประเภท=”รีเซ็ต” มันจะคืนค่าการรีเซ็ตสำหรับองค์ประกอบการรีเซ็ตอินพุตเสมอ
ไวยากรณ์
ต่อไปนี้เป็นไวยากรณ์สำหรับคุณสมบัติประเภทการรีเซ็ต -
resetObject.type
ตัวอย่าง
ให้เราดูตัวอย่างคุณสมบัติประเภทการรีเซ็ต -
<!DOCTYPE html>
<html>
<body>
<h1>Input reset type Property</h1>
<form style="border:solid 2px green;padding:2px">
UserName: <input type="text" id="USR"> <br>
Location: <input type="text" id="Age"> <br><br>
<input type="reset" id="RESET1">
</form>
<p>Get the above input element type by clicking the below button</p>
<button type="button" onclick="resetType()">GET Type</button>
<p id="Sample"></p>
<script>
function resetType() {
var P=document.getElementById("RESET1").type;
document.getElementById("Sample").innerHTML = "The type for the input field is: "+P ;
}
</script>
</body>
</html> ผลลัพธ์
สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ -

เมื่อคลิกคุณสมบัติ GET Type -

ในตัวอย่างข้างต้น −
เราได้สร้าง องค์ประกอบที่มี type=”reset”, id=”RESET1” การคลิกที่ปุ่มนี้จะรีเซ็ตข้อมูลในแบบฟอร์ม ปุ่มนี้อยู่ในแบบฟอร์มที่มีช่องข้อความสองช่อง และแบบฟอร์มยังมีรูปแบบอินไลน์ที่ใช้อยู่ด้วย -
<form style="border:solid 2px green;padding:2px"> UserName: <input type="text" id="USR"> <br> Location: <input type="text" id="Age"> <br><br> <input type="reset" id="RESET1"> </form>
จากนั้นเราได้สร้างปุ่ม "GET Type" ที่จะรันเมธอด resetType() เมื่อผู้ใช้คลิก -
<button type="button" onclick="resetType()">GET Type</button>
วิธี resetType() รับองค์ประกอบอินพุตโดยใช้เมธอด getElementById() และกำหนดค่าแอตทริบิวต์ประเภทให้กับตัวแปร P จากนั้นตัวแปรนี้จะแสดงในย่อหน้าด้วย id "ตัวอย่าง" โดยใช้คุณสมบัติ innerHTML -
function getType() {
var P = document.getElementById("RESET1").type;
document.getElementById("Sample").innerHTML = "The type for the input field is : "+P;
}