คุณสมบัติค่าที่ซ่อนอยู่ของอินพุต HTML DOM ส่งคืนและแก้ไขเนื้อหาของแอตทริบิวต์ค่าของฟิลด์อินพุตประเภท=”ซ่อน” ในเอกสาร HTML
ไวยากรณ์
ต่อไปนี้เป็นไวยากรณ์ -
1. คืนค่า
object.value
2. การปรับเปลี่ยนค่า
object.value=”text”
ตัวอย่าง
ให้เราดูตัวอย่างของ HTML DOM อินพุตคุณสมบัติค่าที่ซ่อนอยู่ -
<!DOCTYPE html>
<html>
<head>
<style>
body{
text-align:center;
background-color:#F19A3E;
color:#fff;
}
.btn{
background-color:#3C787E;
border:none;
height:2rem;
border-radius:50px;
width:60%;
margin:1rem auto;
display:block;
color:#fff;
outline:none;
cursor:pointer;
}
.show{
color:#fff;
font-size:1.2rem;
font-weight:600;
}
</style>
</head>
<body>
<h1>DOM Hidden value Property Example</h1>
Here is hidden input field:
<input type="hidden" class="input-field" value="Hi! I was previous value of hidden input">
<button onclick="getType()" class="btn">Click to change value</button>
<div class="show"></div>
<script>
function getType() {
var inputField = document.querySelector(".input-field");
var msgDiv = document.querySelector(".show");
msgDiv.innerHTML = "" + inputField.value + "";
inputField.value = "Hello! I'm new value of hidden input"
msgDiv.innerHTML +="" + inputField.value + "";
}
</script>
</body>
</html> ผลลัพธ์
สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ -

คอนโซล -

คลิกที่ “คลิกเพื่อเปลี่ยนค่า ” เพื่อเปลี่ยนค่าของช่องป้อนข้อมูลที่ซ่อนอยู่ ดูภาพหน้าจอคอนโซลเพื่อให้เข้าใจได้ง่าย -

คอนโซล -
