Example Description
Next, the user is introduced to a property similar to the read-only property, which is to set the default value of the text box. Set the default color of the text box to gray, and dynamically change the text box default value information when entering information in the user name.
Key Technology
The key to this example is to set the default value of the text box through the disabled attribute, and then dynamically change the value of the default value text box through related events. The code for setting the default value using the disabled attribute is as follows:
<input id="0"class="0"type="text"disabled value='0100521041'/>
Design process
(1) Create a new index.php file, introduce the CSS style sheet file, and write the form. The code is as follows:
table width="350"border="0"class="p"> <tr> <td width="100">用户名:</td> <td align="left"><input class="m"id="name"type="text"/></td> </tr> <tr> <td>职 位:</td> <td align="left"><input class="m"type="text"id="type"disabled value="自选选取"/></td> </tr> </table>
(2) Define a JavaScript script method to dynamically change the default value of the text box. The code is as follows:
$("#name").keyup(function(){ var name=$("#name").val(); var manager='mr'; if(name=='mr'){ $("#type").val("经理"); }else{ $("#type").val("程序员"); } });
Secret Tips
Regarding setting the default value of the text box.
(1) Setting the default value of the text box and setting the read-only attribute of the text box have the same effect.
(2) When using disabled, just add the attribute name to the mark.
The above is the detailed content of How to set default value for input in PHP. For more information, please follow other related articles on the PHP Chinese website!