How to prohibit text in HTML: 1. Use readonly in HTML to prohibit text input; 2. Use disabled in HTML to prohibit text input.
The operating environment of this article: Windows7 system, HTML5&&CSS3 version, Dell G3 computer.
HTML prohibiting text input
In a text box, there are two ways to prohibit text input, one is to use readonly, and the other is to use disabled.
So although the purpose of both Both can be achieved, but from a performance perspective, disabled will appear more intuitive. Why do you say this?
Please see the screenshot:
As shown in the picture:
1 is readonly, 2 is diabled. Obviously it is modified with diabled The text box turns gray. To sum up, it is recommended to use disabled to make the text box unavailable for input.
But for time frames that cannot be entered, it is more recommended to use readonly.
The corresponding codes are as follows:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title></title> <script type="text/javascript" src="../js/lib/jquery-1.8.0.min.js"></script> <script type="text/javascript"> $(function () { $("#readonly").prop("readonly", true); $("#disable").prop("disabled", true); }) </script> </head> <body> <input id="readonly" type="text"> <input id="disable" type="text"> </body> </html>
Recommended tutorials: html video tutorial, css video tutorial
The above is the detailed content of How to prohibit text in html. For more information, please follow other related articles on the PHP Chinese website!