Detailed explanation of HTML's tag and how to disable it_HTML/Xhtml_Web page production

WBOY
Release: 2016-05-16 16:36:30
Original
1468 people have browsed it

Definition and usage
tag is used to collect user information.
According to different type attribute values, input fields have many forms. Input fields can be text fields, checkboxes, masked text controls, radio buttons, buttons, etc.
Differences between HTML and XHTML
In HTML, the tag does not have a closing tag.
In XHTML, the tag must be closed properly.
Example
A simple HTML form containing two text input boxes and a submit button:

XML/HTML CodeCopy content to clipboard
  1. <form action="form_action.asp" method="get">
  2. First name: <input type= "text" name="fname" />
  3. Last name: <input type= "text" name="lname" />
  4. <input type="submit" value="Submit" />
  5. form>

The disabled attribute specifies that the input element should be disabled.
A disabled input element is neither available nor clickable. The disabled attribute can be set until some other condition is met (such as a checkbox being selected, etc.). Then, you need to use JavaScript to remove the disabled value and switch the value of the input element to available.
201585180424922.jpg (205×270)

The following three writing methods can disable input

XML/HTML CodeCopy content to clipboard
  1. <input type="text" disabled="disabled" value="Disabled" />
  2. <input type="text" disabled="disabled" value="Disabled" />
  3. <input type="text" disabled="disabled" value="Disabled" />

Disabled inputs are gray by default and can be styled through CSS. Note: IE9 and below cannot change the font color
1. Use CSS3 :disabled pseudo-element definition

CSS CodeCopy content to clipboard
  1. //Chrome Firefox Opera Safari
  2. input:disabled{
  3. border: 1px solid #DDD;
  4. background-color: #F5F5F5;
  5.  color:#ACA899
  6. }

2. Use attribute selectors to define

CSS CodeCopy content to clipboard
  1. //IE6 failed
  2. input[disabled]{
  3. border: 1px solid #DDD;
  4. background-color: #F5F5F5;
  5.  color:#ACA899
  6. }

3. Use class to define and add a class for the input to be disabled

CSS CodeCopy content to clipboard
  1. input.disabled{
  2. border: 1px solid #DDD;
  3. background-color: #F5F5F5;
  4.  color:#ACA899
  5. }

Final result:

CSS CodeCopy content to clipboard
  1. //Chrome Firefox Opera Safari IE9
  2. input:disabled{
  3. border: 1px solid #DDD;
  4. background-color: #F5F5F5;
  5.  color:#ACA899
  6. }
  7. //IE8-
  8. input[disabled]{
  9. border: 1px solid #DDD;
  10. background-color: #F5F5F5;
  11.  color:#ACA899
  12. }
  13. //IE6 Using Javascript to add CSS class "disabled"
  14. * html input.disabled{
  15. border: 1px solid #DDD;
  16. background-color: #F5F5F5;
  17.  color:#ACA899
  18. }

Note: IE8 bug
Because IE8 does not recognize :disabled, the input[disabled] and input:disabled styles become invalid. You can consider writing them separately, or use input[disabled] directly. ;The font color cannot be changed in IE9 and below.

Demo

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!