DOM 'disabled' property in javascript

前端 未结 5 1637
半阙折子戏
半阙折子戏 2020-12-21 02:59

I can\'t find a definitive answer to how to use the disabled property to disable form elements in javascript.

Some places say it\'s a simple boolean. Other\'s say to

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-21 03:19

    The disabled attribute is a boolean. If the tag is present the input will be disabled. The confusion around having a string value associated with it usually comes from XHTML validation. In XHTML attribute minimization is forbidden, so it must have a value, and XHTML specification states it must be disabled="disabled".

    For any browser, if the tag is present, the input will be disabled, regardless of the string value.

    JsFiddle Demo

    w3c disabled attribute spec

提交回复
热议问题