HTML DOM इनपुट नंबर defaultValue प्रॉपर्टी एक HTML दस्तावेज़ में टाइप ="नंबर" के इनपुट फ़ील्ड के डिफ़ॉल्ट मान को लौटाती है और संशोधित करती है।
सिंटैक्स
निम्नलिखित सिंटैक्स माइनस है;
-
डिफ़ॉल्ट मान लौटा रहा है
object.defaultValue
-
डिफ़ॉल्ट मान को संशोधित करना
object.defaultValue=”number”
उदाहरण
आइए HTML DOM इनपुट नंबर डिफॉल्टवैल्यू प्रॉपर्टी का एक उदाहरण देखें-
<!DOCTYPE html>
<html>
<head>
<style>
html{
height:100%;
}
body{
text-align:center;
color:#fff;
background: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%) center/cover no-repeat;
height:100%;
}
p{
font-weight:700;
font-size:1.2rem;
}
input{
width:35%;
border:2px solid #fff;
background-color:transparent;
color:#fff;
font-weight:bold;
padding:8px;
}
.btn{
background:#0197F6;
border:none;
height:2rem;
border-radius:2px;
width:35%;
margin:2rem auto;
display:block;
color:#fff;
outline:none;
cursor:pointer;
}
.show{
font-size:1.5rem;
font-weight:bold;
}
</style>
</head>
<body>
<h1>DOM Input number defaultValue Example</h1>
<p>Hi, Enter your day of birth</p>
<input type="number" class="numberInput">
<button onclick="changeValue()" class="btn">Submit</button>
<div class="show"></div>
<script>
function changeValue() {
var numberInput = document.querySelector(".numberInput");
var showMsg = document.querySelector(".show");
numberInput.defaultValue = "20";
numberInput.value= numberInput.defaultValue;
showMsg.innerHTML ="Tada! I changed your day of birth into mine!";
}
</script>
</body>
</html> आउटपुट
यह निम्नलिखित परिणाम देगा -

अपना जन्म दिन दर्ज करें और फिर “सबमिट करें . पर क्लिक करें अपने मान को डिफ़ॉल्ट मान में बदलने के लिए बटन।

