परिचय
HTML DOM इनपुट नंबर readOnly प्रॉपर्टी HTML दस्तावेज़ में इनपुट नंबर फील्ड के रीड-ओनली होने या न होने का मान प्राप्त करती है और संशोधित करती है।
सिंटैक्स
मान प्राप्त करना
object.readOnly
मान सेट करना
object.readOnly = true | false
उदाहरण
नंबर इनपुट फील्ड को रीड-ओनली और रीड-राइट के बीच टॉगल करना:
<!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;
outline: none;
}
.btn {
background: #0197F6;
border: none;
height: 2rem;
border-radius: 2px;
width: 35%;
margin: 2rem auto;
display: block;
color: #fff;
outline: none;
cursor: pointer;
}
</style>
</head>
<body>
<h1>DOM इनपुट नंबर readOnly प्रॉपर्टी डेमो</h1>
<p>हाय, अपनी जन्म तिथि का दिन चुनें?</p>
<input type="number" class="numberInput">
<button onclick="rFunction()" class="btn">रीड ओनली</button>
<button onclick="rWFunction()" class="btn">रीड एंड राइट</button>
<script>
function rFunction() {
var monthInput = document.querySelector(".numberInput");
monthInput.readOnly = true;
}
function rWFunction() {
var monthInput = document.querySelector(".numberInput");
monthInput.readOnly = false;
}
</script>
</body>
</html>
आउटपुट
"रीड ओनली" और "रीड एंड राइट" बटन पर क्लिक करके देखें कि readOnly प्रॉपर्टी कैसे काम करती है।