disabled & readonly的差別?

這篇解答的很好, 回答的人也是從文章中抓重點寫的,

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

http://stackoverflow.com/questions/7730695/whats-the-difference-between-disabled-disabled-and-readonly-readonly-for-ht

1. a readonly element is just not editable, but gets sent when the according form submits.

2. a disabled element isn't editable and isn't sent on submit.

3. 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 <SELECT> , <OPTION> , and <BUTTON> elements do not have readonly attributes (although thy both have disabled attributes)

--> Browsers provide no default overridden visual feedback that the form element is read only. (This can be a problem… see below.)

--> Form elements with the readonly attribute set will get passed to the form processor.

--> Read only form elements can receive the focus

--> Read only form elements are included in tabbed navigation.



留言

熱門文章