HTML DOM Input Number defaultValue Property
HTML DOM input number defaultValue property HTML दस्तावेज़ में type="number" वाले इनपुट फील्ड का डिफ़ॉल्ट मान प्राप्त या संशोधित करता है। यह वह मान है जो पेज लोड होने पर इनपुट में होता है, और फॉर्म रीसेट होने पर इसी मान पर वापस आता है।
Syntax
डिफ़ॉल्ट मान प्राप्त करना:
numberInputObject.defaultValue
डिफ़ॉल्ट मान सेट करना:
numberInputObject.defaultValue = "number"
उदाहरण
जन्म तिथि इनपुट जहां बटन क्लिक करने पर डिफ़ॉल्ट मान (20) सेट हो जाता है:
<!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>नमस्ते, अपनी जन्म तिथि दर्ज करें</p>
<input type="number" class="numberInput">
<button onclick="changeValue()" class="btn">सबमिट</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 = "तडा! मैंने आपकी जन्म तिथि को अपनी में बदल दी!";
}
</script>
</body>
</html>
आउटपुट
अपनी जन्म तिथि दर्ज करें और "सबमिट" बटन पर क्लिक करें। आपका मान डिफ़ॉल्ट मान (20) में बदल जाएगा।
मुख्य बिंदु
defaultValueपेज लोड होने पर इनपुट का प्रारंभिक मान दर्शाता हैvalueproperty वर्तमान मान दर्शाता है, जो उपयोगकर्ता द्वारा बदला जा सकता है- फॉर्म रीसेट (
form.reset()) होने परvalueवापसdefaultValueपर आ जाता है defaultValueबदलने से वर्तमानvalueस्वचालित रूप से नहीं बदलता- HTML में
valueattribute सेट करने सेdefaultValueभी सेट होता है