Html 输入文本元素的正确只读属性语法是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16109358/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 07:41:05  来源:igfitidea点击:

What is the correct readonly attribute syntax for input text elements?

htmlformsreadonlyinput-field

提问by Obmerk Kronen

As Most, I am familiar with the readonlyattribute for text input, But while reading code from other websites (a nasty habit of mine ) I saw more than one implementation for this attribute:

与大多数人一样,我熟悉readonlyfor的属性text input,但是在阅读其他网站的代码时(我的一个坏习惯),我看到了此属性的多个实现:

<input type="text" value="myvalue" class="class anotherclass" readonly >

and

<input type="text" value="myvalue" class="class anotherclass" readonly="readonly" >

and I have even seen

我什至见过

<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?

那么,我应该使用哪一种是正确的呢?

回答by Vucko

From w3:

w3

readonly= "readonly"or "" (empty string)or empty- Specifies that element represents a control whose value is not meant to be edited.

readonly= "readonly"""(空字符串)- 指定该元素表示其值不打算编辑的控件。

So basically it's the same.

所以基本上是一样的。

回答by billah77

is should be

应该是

<input type="text" value="myvalue" class="class anotherclass" readonly="readonly" />