DOM 'disabled' property in javascript

前端 未结 5 1639
半阙折子戏
半阙折子戏 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:18

    The existence of the property is enough to trigger the disabled state.

    If you must set a value for the property then it should be the same as the property name e.g disabled="disabled".

    I'll try to find some documentation on the specific behaviours of browsers and the relevant specs.

    --edit--

    The HTML5 spec covers boolean attributes, such as disabled, here: http://www.w3.org/html/wg/drafts/html/master/infrastructure.html#boolean-attributes

    In practice, web browsers will ignore the assigned value and simply look for the presence of the attribute.

提交回复
热议问题