Detailed explanation of HTML's <input> tag and how to disable it

Detailed explanation of HTML's <input> tag and how to disable it

Definition and Usage
The <input> tag is used to collect user information.
Depending on the value of the type attribute, the input field can have many forms. Input fields can be text fields, check boxes, masked text controls, radio buttons, buttons, and so on.
Differences between HTML and XHTML
In HTML, the <input> tag has no closing tag.
In XHTML, <input> tags must be properly closed.
Examples
A simple HTML form with 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 usable nor clickable. The disabled property 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 enabled.
201585180424922.jpg (205×270)

The following three ways 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 input is grayed out by default and can be styled using 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. Define using attribute selectors

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 to 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
Since IE8 does not recognize :disabled, the input[disabled] and input:disabled styles are invalid. You can consider writing them separately or using input[disabled] directly. ; IE9 and below cannot change the font color.

Demo

<<:  How to use MySQL binlog to restore accidentally deleted databases

>>:  Floating menu, can achieve up and down scrolling effect

Recommend

Comparing Document Locations

<br />A great blog post by PPK two years ago...

How to build Apr module for tomcat performance optimization

Preface Tomcat is a widely used Java web containe...

Zabbix WEB monitoring implementation process diagram

Take zabbix's own WEB interface as an example...

HTML implements a fixed floating semi-transparent search box on mobile

Question. In the mobile shopping mall system, we ...

A brief analysis of React's understanding of state

How to define complex components (class component...

Docker volume deletion operation

prune To use this command, both the client and da...

A universal nginx interface to implement reverse proxy configuration

1. What is a proxy server? Proxy server, when the...

Vue shuttle box realizes up and down movement

This article example shares the specific code for...

Understanding the CSS transform-origin property

Preface I recently made a fireworks animation, wh...

How to build php-nginx-alpine image from scratch in Docker

Although I have run some projects in Docker envir...

Summary of three ways to implement ranking in MySQL without using order by

Assuming business: View the salary information of...

Native js custom right-click menu

This article example shares the specific code of ...

Solve the problem that Mysql5.7.17 fails to install and start under Windows

Install MySQL for the first time on your machine....

Example code for css flex layout with automatic line wrapping

To create a flex container, simply add a display:...