如何在此代码中只读文本框

时间:2015-02-21 10:33:19

标签: php html forms

<label class="control-label" for="inputEmail">First Name:</label>
<div class="controls">
<input type="text" class="span4" id="inputEmail" name="firstname"  value="<?php echo $row['firstname']; ?>" placeholder="First Name" required>
<input type="hidden" id="inputEmail" name="id" value="<?php echo $get_id;  ?>" placeholder="First Name" required>     

2 个答案:

答案 0 :(得分:1)

如果您只想使文本字段可读,请使用 readonly 属性。

示例:

<input type="text"value="foo"readonly>

来自您的代码

<label class="control-label" for="inputEmail">First Name:</label>
<div class="controls">
<input type="text" class="span4" id="inputEmail" name="firstname"  value="<?php echo $row['firstname']; ?>" placeholder="First Name"readonly>
<input type="hidden" id="inputEmail" name="id" value="<?php echo $get_id;  ?>" placeholder="First Name" readonly>     

答案 1 :(得分:0)

如果您想将inputEmail设为只读字段,可以使用

<label class="control-label" for="inputEmail">First Name:</label>
<div class="controls">
<input type="text" class="span4" id="inputEmail" name="firstname"  value="<?php echo $row['firstname']; ?>" placeholder="First Name" required readonly>
<input type="hidden" id="inputEmail" name="id" value="<?php echo $get_id;  ?>" placeholder="First Name" required>  

请注意,我在第3行的输入标记的末尾添加了readonly。