How to Control the Enabled State of HTML Input Buttons
You want to have the option to disable and enable an HTML button dynamically. Here's how you can achieve this:
Using JavaScript
To disable the button, use the following code:
<code class="javascript">document.getElementById("Button").disabled = true;</code>
To enable the button, use:
<code class="javascript">document.getElementById("Button").disabled = false;</code>
Using jQuery
For jQuery versions prior to 1.6:
Disable the button:
<code class="javascript">$('#Button').attr('disabled','disabled');</code>
Enable the button:
<code class="javascript">$('#Button').removeAttr('disabled');</code>
For jQuery versions 1.6 and later:
Disable the button:
<code class="javascript">$('#Button').prop('disabled', true);</code>
Enable the button:
<code class="javascript">$('#Button').prop('disabled', false);</code>
Code Demo
Refer to the provided demos for practical examples of how to disable and enable a button dynamically.
The above is the detailed content of Here are a few question-based titles based on your article content: Short & Simple: * How Do I Disable and Enable HTML Input Buttons? * Want to Control HTML Button States? Here\'s How! * Dynamic. For more information, please follow other related articles on the PHP Chinese website!