HTML DOM Button disabled प्रॉपर्टी <button> एलिमेंट के disabled एट्रिब्यूट से जुड़ी है। button disabled प्रॉपर्टी का उपयोग यह सेट या लौटाने के लिए किया जाता है कि दिया गया बटन अक्षम है या नहीं। इसका उपयोग बटन को अक्षम करने के लिए किया जाता है ताकि यूज़र निर्दिष्ट एलिमेंट के साथ अब इंटरैक्ट न कर सके। disabled प्रॉपर्टी सेट करने से वेब ब्राउज़र्स में डिफ़ॉल्ट रूप से बटन ग्रे हो जाएगा।
सिंटैक्स
निम्नलिखिक सिंटैक्स है -
disabled प्रॉपर्टी सेट करना -
buttonObject.disabled = true|false
यहां, true|false निर्दिष्ट करता है कि दिया गया इनपुट बटन अक्षम होना चाहिए या नहीं।
- True − बटन अक्षम हो जाता है।
- False − बटन अक्षम नहीं होगा।
आइए button disabled प्रॉपर्टी का एक उदाहरण देखें -
उदाहरण
<!DOCTYPE html> <html> <body> <button id="Button1">BUTTON</button> <p>Click the below button to disable the above button.</p> <button onclick="buttonDis()">CLICK IT</button> <p id="Sample"> <script> function buttonDis() { document.getElementById("Button1").disabled = true; var x=document.getElementById("Button1").disabled; document.getElementById("Sample").innerHTML = "Button disabled is "+x; } </script> </body> </html>
आउटपुट
यह निम्नलिखिक आउटपुट उत्पन्न करेगा -

CLICK IT बटन पर क्लिक करने पर -

उपरोक्त उदाहरण में -
हमने id “Button1” के साथ एक बटन बनाया है और बटन डिफ़ॉल्ट रूप से सक्षम है।
<button id="Button1">BUTTON</button>
फिर हमारे पास buttonDis() मेथड को क्लिक पर निष्पादित करने के लिए CLICK IT बटन है।
<button onclick="buttonDis()">CLICK IT</button>
buttonDis() मेथड इसकी id “button1” द्वारा बटन एलिमेंट को प्राप्त करता है और इस पर disabled एट्रिब्यूट को true पर सेट करता है। बटन को अक्षम करने के बाद इसका disabled मान (true या false) वेरिएबल x को असाइन किया जाता है और id “Sample” वाले पैराग्राफ में प्रदर्शित किया जाता है
function buttonDis() { document.getElementById("Button1").disabled = true; var x=document.getElementById("Button1").disabled; document.getElementById("Sample").innerHTML = "Button disabled is "+x; }