disabledプロパティが存在しないと出てきます。
下記の部分です・
if(hintBtn.disabled === 'disabled')
周辺のソースは下記に記載しました。
https://codepen.io/anon/pen/wjbebe
仕様上disabledプロパティは、始めは存在しないのでしょうか?
気になる質問をクリップする
クリップした質問は、後からいつでもMYページで確認できます。
またクリップした質問に回答があった際、通知やメールを受け取ることができます。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
回答2件
0
まだ何も代入していないので、hintBtnはundefinedでは?
投稿2018/05/25 04:37
総合スコア13749
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/05/25 05:17
2018/05/25 06:29
2018/05/25 06:37
2018/05/25 06:39
退会済みユーザー
2018/05/25 06:42
2018/05/25 06:44
2018/05/25 06:46
退会済みユーザー
2018/05/25 06:59
2018/05/25 07:04
2018/05/25 07:05
退会済みユーザー
2018/05/25 07:09
2018/05/25 07:13
退会済みユーザー
2018/05/25 07:23
0
ベストアンサー
if(hintBtn.disabled === 'disabled')
disabled
プロパティの値はbool値です。
https://developer.mozilla.org/ja/docs/Web/API/HTMLInputElement
なので、if(hintBtn.disabled === 'disabled')
の条件式だと常にfalse
が返ります。
正しくは、if(hintBtn.disabled === true)
か、if(hintBtn.disabled === false)
です。
もしくは、if(hintBtn.disabled)
か、if(!hintBtn.disabled)
です。
https://codepen.io/anon/pen/JvQyQX
参考
4.10.19.5 Enabling and disabling form controls: the disabled attribute
The disabled content attribute is a boolean attribute.
A form control is disabled if its disabled attribute is set, or if it is a descendant of a fieldset element whose disabled attribute is set and is not a descendant of that fieldset element's first legend element child, if any.
A form control that is disabled must prevent any click events that are queued on the user interaction task source from being dispatched on the element.
Constraint validation: If an element is disabled, it is barred from constraint validation.
The disabled IDL attribute must reflect the disabled content attribute.
https://www.w3.org/TR/2018/SPSD-html5-20180327/forms.html#concept-fe-disabled
2.4.2 Boolean attributes
A number of attributes are boolean attributes. The presence of a boolean attribute on an element represents the true value, and the absence of the attribute represents the false value.
If the attribute is present, its value must either be the empty string or a value that is an ASCII case-insensitive match for the attribute's canonical name, with no leading or trailing whitespace.
The values "true" and "false" are not allowed on boolean attributes. To represent a false value, the attribute has to be omitted altogether.
Here is an example of a checkbox that is checked and disabled. The checked and disabled attributes are the boolean attributes.
<label><input type=checkbox checked name=cheese disabled> Cheese</label> This could be equivalently written as this: <label><input type=checkbox checked=checked name=cheese disabled=disabled> Cheese</label> You can also mix styles; the following is still equivalent: <label><input type='checkbox' checked name=cheese disabled=""> Cheese</label>
https://www.w3.org/TR/2018/SPSD-html5-20180327/infrastructure.html#boolean-attribute
投稿2018/05/25 07:17
編集2018/05/25 08:47総合スコア2415
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/05/25 07:30
2018/05/25 07:33
2018/05/25 07:37
退会済みユーザー
2018/05/25 07:46
2018/05/25 08:02 編集
あなたの回答
tips
太字
斜体
打ち消し線
見出し
引用テキストの挿入
コードの挿入
リンクの挿入
リストの挿入
番号リストの挿入
表の挿入
水平線の挿入
プレビュー
質問の解決につながる回答をしましょう。 サンプルコードなど、より具体的な説明があると質問者の理解の助けになります。 また、読む側のことを考えた、分かりやすい文章を心がけましょう。