Html 不允许输入的html文本框表单

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2355450/
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 02:21:11  来源:igfitidea点击:

html text box form that will not allow input

html

提问by user225269

Is there any class in an html form that does not allow you to input or change the value in that text box. But you can see its content , for example the code below will allow you to see the content of the record in mysql database. But what I want is for it not to be edited. What would I add to the code below so that its content will not be editted by the users:

html 表单中是否有任何类不允许您输入或更改该文本框中的值。但是你可以看到它的内容,例如下面的代码可以让你看到mysql数据库中记录的内容。但我想要的是它不被编辑。我会在下面的代码中添加什么,以便用户不会编辑其内容:

   <tr>
<td><font size="3">Civil Status</td>
<td>:</td>
<td><input name="cs" type="text" maxlength="7" value="<?php echo $row["CSTAT"]; ?>"></td>
<td><font size="3">Age</td>
<td>:</td>
<td><input name="age" type="text" maxlength="3" value="<?php echo $row["AGE"]; ?>"></td>
<td><font size="3">Birthday</td>
<td>:</td>
<td><input name="bday" type="text" maxlength="12" value="<?php echo $row["BDAY"]; ?>"></td>

</tr>

<tr>
<td><font size="3">Address</td>
<td>:</td>
<td><input name="ad" type="text" maxlength="25" value="<?php echo $row["ADDRESS"]; ?>"></td>
<td><font size="3">Telephone #</td>
<td>:</td>
<td><input name="telnum" type="text" maxlength="11" value="<?php echo $row["TELNUM"]; ?>"></td>

<td width="23"><font size="3">Sex</td>
<td width="3">:</td>
<td width="174"><input name="sex" type="text"  maxlength="1" value="<?php echo $row["SEX"]; ?>"></td>
</tr>

回答by Daniel Vassallo

What about the readonly attribute?

怎么样的只读属性

<input type="text" name="telnum" value="123456" readonly="readonly" />

回答by Andy Shellam

You can put readonly="readonly"in your <input>tag. You can also use disabled="disabled". Both provide varying degrees of "disabled-ness" as demonstrated here.

你可以把readonly="readonly"你的<input>标签。您也可以使用disabled="disabled". 两者都提供了不同程度的“残疾性”的在这里展示

This is not fail-safe, though. Make sure that you do check when the form is POSTed back if the value has been modified - someone can craft a valid POST request with the field value modified - there's nothing you can do about that except check on the server-side if it's been modified from what it was originally.

不过,这并不是万无一失的。如果该值已被修改,请确保您在回发表单时进行检查 - 有人可以制作一个有效的 POST 请求并修改字段值 - 除了在服务器端检查它是否已被修改之外,您无能为力从它最初的样子。

回答by Ignacio Vazquez-Abrams

If you don't want it edited, and if there's no reason for it ever to beedited, then it shouldn't be in an inputelement at all. Just echo it as normal text.

如果您不想对其进行编辑,并且没有理由对其进行编辑,那么它根本不应该位于input元素中。只需将其作为普通文本回显即可。

回答by hearn

Use the readonly attribute

使用只读属性

<input readonly="value" />

http://www.w3schools.com/tags/att_input_readonly.asp

http://www.w3schools.com/tags/att_input_readonly.asp

回答by Nikhil Mahirrao

You can try "disabled" OR "readonly"

您可以尝试“禁用”或“只读

<form> 
  <label for="disabled">Disabled</label><br> 
  <input name="disabled" value="disabled" disabled>
  <br><br>
  <label for="readonly">Read Only</label><br> 
  <input name="readonly" value="readonly" readonly> 
</form>