Home > Web Front-end > JS Tutorial > 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

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

Patricia Arquette
Release: 2024-10-27 00:20:30
Original
750 people have browsed it

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!
* Dynamically Enable/Disable HTML Buttons: A Quick Guide

More Speci

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>
Copy after login

To enable the button, use:

<code class="javascript">document.getElementById("Button").disabled = false;</code>
Copy after login

Using jQuery

For jQuery versions prior to 1.6:

Disable the button:

<code class="javascript">$('#Button').attr('disabled','disabled');</code>
Copy after login

Enable the button:

<code class="javascript">$('#Button').removeAttr('disabled');</code>
Copy after login

For jQuery versions 1.6 and later:

Disable the button:

<code class="javascript">$('#Button').prop('disabled', true);</code>
Copy after login

Enable the button:

<code class="javascript">$('#Button').prop('disabled', false);</code>
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template