disabled 和 readonly 在应用中一直的使用,但是没有去深入研究到底有区别,这里查找了一些资料来记录一下
主要的区别我认为是:
1:说有的标签都有disabled属性,包括div;但是不是所有的属性都有readonly属性,比如select , button,
2:readonly属性可以被js代码改变,用getElementById('id').value(value);仍旧是可以改变属性的值,disabled就不能了
3:readonly表示过的表单字段还是会被提交给服务器的,但是disabled的字段不提交
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.
这个是在stackoverflow中的参考:
http://stackoverflow.com/questions/7730695/whats-the-difference-between-disabled-disabled-and-readonly-readonly-for-ht
这篇文字有关于w3c的标准
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.
还有一篇很详细的关于两个标签的区别的文章:
http://www.cnblogs.com/WeAreEpms/archive/2008/12/28/1364166.html
一定要看这篇文章,总结的非常的到位