html中 disabled readonly

disabled 和 readonly 在应用中一直的使用,但是没有去深入研究到底有区别,这里查找了一些资料来记录一下


主要的区别我认为是:

1:说有的标签都有disabled属性,包括div;但是不是所有的属性都有readonly属性,比如select , button,

2:readonly属性可以被js代码改变,用getElementById('id').value(value);仍旧是可以改变属性的值,disabled就不能了

3:readonly表示过的表单字段还是会被提交给服务器的,但是disabled的字段不提交

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 readonlyelements can be focused (and getting focused when "tabbing" through a form) while disabledelements 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


一定要看这篇文章,总结的非常的到位

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值