188
186

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

jQueryのprop()でdisabled属性を切り替える

Last updated at Posted at 2014-10-10

buttonタグなどのdisabled属性の切り替えを、jQueryのprop()によって切り替える方法です。

ボタンのHTML
<button id="pugi">送信</button>

disabledを外す場合

ボタンを有効にする
$("#pugi").prop("disabled", false);

disabledが外れてボタンが有効になります。

disabledをつける場合

ボタンを無効にする
$("#pugi").prop("disabled", true);

disabledがついてボタンが無効になります。

おまけ

disabled属性をつけるとサーバーと通信してくれません。通信したい場合はreadonly属性を使います。

188
186
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
188
186

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?