输入文本元素的正确只读属性语法是什么?
问题描述:
和大多数人一样,我熟悉 text input
的 readonly
属性,但是在阅读其他网站的代码时(我的一个坏习惯),我看到了不止一个此属性的实现:
As Most, I am familiar with the readonly
attribute for text input
, But while reading code from other websites (a nasty habit of mine ) I saw more than one implementation for this attribute:
<input type="text" value="myvalue" class="class anotherclass" readonly >
和
<input type="text" value="myvalue" class="class anotherclass" readonly="readonly" >
我什至见过
<input type="text" value="myvalue" class="class anotherclass" readonly="true" >
.. 我相信我看到了更多,但现在想不起来确切的语法了..
.. And I believe I saw even more, but can not recall the exact syntax now..
那么,我应该使用哪一个是正确的?
So, which one is the correct one that I should use?
答
来自 w3:
readonly = "readonly" 或 ""(空字符串) 或 empty -指定该元素表示其值不可编辑的控件.
readonly = "readonly" or "" (empty string) or empty - Specifies that element represents a control whose value is not meant to be edited.
所以基本上是一样的.