HTML DOM Input Number max Property
HTML DOM input number max property HTML दस्तावेज़ में type="number" वाले इनपुट फील्ड के max attribute का मान प्राप्त या संशोधित करता है। यह उपयोगकर्ता द्वारा दर्ज की जा सकने वाली अधिकतम संख्या को परिभाषित करता है।
Syntax
Max मान प्राप्त करना:
numberInputObject.max
Max मान सेट करना:
numberInputObject.max = "number"
उदाहरण
रोल नंबर इनपुट फील्ड जिसमें न्यूनतम 1 और अधिकतम 60 की सीमा है (min property के समान उदाहरण):
<!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.1rem; }
input {
display: block;
width: 35%;
border: 2px solid #fff;
background-color: transparent;
color: #fff;
font-weight: bold;
padding: 8px;
margin: 1rem auto;
}
.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 max/min property Demo</h1>
<p>अपना रोल नंबर दर्ज करें (1 से 60 के बीच)</p>
<input type="number" class="numberInput" min="1" max="60">
<button type="button" onclick="showMySelection()" class="btn">रोल नंबर दिखाएं</button>
<div class="show"></div>
<script>
function showMySelection() {
var numberInput = document.querySelector(".numberInput");
var showMsg = document.querySelector(".show");
console.log(numberInput.min, numberInput.max);
if (numberInput.value === '') {
showMsg.innerHTML = "कृपया मान दर्ज करें!!";
} else {
if (numberInput.value >= 1 && numberInput.value <= 60) {
showMsg.innerHTML = numberInput.value;
} else {
showMsg.innerHTML = "कृपया सही रोल नंबर दर्ज करें!!";
}
}
}
</script>
</body>
</html>
आउटपुट
1 से 60 के बीच कोई रोल नंबर दर्ज करें और "रोल नंबर दिखाएं" बटन पर क्लिक करें। यदि मान सीमा के भीतर है तो वह प्रदर्शित होगा, अन्यथा चेतावनी संदेश दिखेगा।
मुख्य बिंदु
maxattribute संख्या इनपुट के लिए अधिकतम स्वीकार्य मान परिभाषित करता है- ब्राउज़र स्वचालित रूप से मान्य करता है कि दर्ज मान max से अधिक तो नहीं है
- JavaScript से
input.maxproperty द्वारा इसे पढ़/लिख सकते हैं minऔरmaxसाथ में उपयोग करके संख्या सीमा परिभाषित करें- मान string के रूप में सेट किया जाता है लेकिन संख्या के रूप में कार्य करता है