Is there a way for me to make an <input> field non-editable
I have some fields that are currently input fields. Some should allow edits and others not. Without changing them from input fields, is there a simple way to make i开发者_运维问答t so I cannot edit these? I'm looking for just one CSS or other kind of property if that exists.
thanks
Mariko
You can add the readonly="readonly" attribute to the input elements.
Or disabled
: <input disabled>
You can style both with CSS:
input:disabled
or input[disabled]
for disabled
input[readonly]
for readonly
<input type="text" id="id" name="id" value="" readonly="readonly" />
either
<textarea ... readonly="readonly"></textarea>
and/or :
<textarea ... disabled="true"></textarea>
I prefer readonly -attribute, which just prevents modifying. Disabled attribute makes the whole area look disabled (grey) and disabled textarea's data isn't submitted, when a form is posted.
精彩评论