परिचय
HTML DOM इनपुट मंथ defaultValue प्रॉपर्टी HTML दस्तावेज़ में type="month" वाले इनपुट फील्ड का डिफ़ॉल्ट मान प्राप्त करती है और संशोधित करती है।
सिंटैक्स
डिफ़ॉल्ट मान प्राप्त करना
object.defaultValue
डिफ़ॉल्ट मान सेट करना
object.defaultValue = value
यहां value स्ट्रिंग के रूप में कोई भी तारीख हो सकती है, जैसे "2019-03"
उदाहरण
मंथ इनपुट का डिफ़ॉल्ट मान बदलकर यूज़र के चयन को ओवरराइड करना:
<!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 इनपुट मंथ defaultValue उदाहरण</h1>
<p>हाय, अपनी जन्म तिथि का महीना दर्ज करें</p>
<input type="month" class="monthInput">
<button onclick="changeValue()" class="btn">सबमिट</button>
<div class="show"></div>
<script>
function changeValue() {
var monthInput = document.querySelector(".monthInput");
var showMsg = document.querySelector(".show");
monthInput.defaultValue = "1997-10";
monthInput.value = monthInput.defaultValue;
showMsg.innerHTML = ":D हेहे मैंने आपकी जन्म तिथि को अपनी डिफ़ॉल्ट तिथि में बदल दिया!";
}
</script>
</body>
</html>
आउटपुट
अपना महीना चुनने के बाद "सबमिट" पर क्लिक करने पर, आपका चयन "अक्टूबर 1997" से बदल जाएगा।