What's the difference between disabled=“disabled” and readonly=“readonly” for HTML form input fields?

后端 未结 5 1513
执笔经年
执笔经年 2020-11-22 04:17

I have read a bit on this, but I can\'t seem to find anything solid about how different browsers treat things.

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-22 04:52

    A readonly element is just not editable, but gets sent when the according form submits. A disabled element isn't editable and isn't sent on submit. Another difference is that readonly elements can be focused (and getting focused when "tabbing" through a form) while disabled elements can't.

    Read more about this in this great article or the definition by w3c. To quote the important part:

    Key Differences

    The Disabled attribute

    • Values for disabled form elements are not passed to the processor method. The W3C calls this a successful element.(This works similar to form check boxes that are not checked.)
    • Some browsers may override or provide default styling for disabled form elements. (Gray out or emboss text) Internet Explorer 5.5 is particularly nasty about this.
    • Disabled form elements do not receive focus.
    • Disabled form elements are skipped in tabbing navigation.

    The Read Only Attribute

    • Not all form elements have a readonly attribute. Most notable, the
    提交评论

提交回复
热议问题