欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

詳解HTML的<input> 標(biāo)簽及其禁用方法

WEB前端開發(fā)   發(fā)布時間:2015-08-05 18:10:49   作者:佚名   我要評論
這篇文章主要介紹了詳解HTML的input標(biāo)簽及其禁用方法,歸納了幾種CSS中使用disabled屬性實(shí)現(xiàn)禁用的方法,需要的朋友可以參考下

定義和用法
<input> 標(biāo)簽用于搜集用戶信息。
根據(jù)不同的 type 屬性值,輸入字段擁有很多種形式。輸入字段可以是文本字段、復(fù)選框、掩碼后的文本控件、單選按鈕、按鈕等等。
HTML 與 XHTML 之間的差異
在 HTML 中,<input> 標(biāo)簽沒有結(jié)束標(biāo)簽。
在 XHTML 中,<input> 標(biāo)簽必須被正確地關(guān)閉。
實(shí)例
一個簡單的 HTML 表單,包含兩個文本輸入框和一個提交按鈕:

XML/HTML Code復(fù)制內(nèi)容到剪貼板
  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>  

其中disabled 屬性規(guī)定應(yīng)該禁用 input 元素。
被禁用的 input 元素既不可用,也不可點(diǎn)擊??梢栽O(shè)置 disabled 屬性,直到滿足某些其他的條件為止(比如選擇了一個復(fù)選框等等)。然后,就需要通過 JavaScript 來刪除 disabled 值,將 input 元素的值切換為可用。
201585180424922.jpg (205×270)

以下三種寫法都可以禁用 input
 

XML/HTML Code復(fù)制內(nèi)容到剪貼板
  1. <input type="text" disabled="disabled" value="已禁用" />  
  2. <input type="text" disabled="disabled" value="已禁用" />  
  3. <input type="text" disabled="disabled" value="已禁用" />  

被禁用的 input 默認(rèn)顯示灰色,可以通過CSS修改樣式。注:IE9及以下無法改變字體顏色
1. 利用CSS3 :disabled 偽元素定義
 

CSS Code復(fù)制內(nèi)容到剪貼板
  1. //Chrome Firefox Opera Safari   
  2. input:disabled{   
  3.     border1px solid #DDD;   
  4.     background-color#F5F5F5;   
  5.     color:#ACA899;   
  6. }  

2. 利用屬性選擇符定義
 

CSS Code復(fù)制內(nèi)容到剪貼板
  1. //IE6 failed   
  2. input[disabled]{   
  3.     border1px solid #DDD;   
  4.     background-color#F5F5F5;   
  5.     color:#ACA899;   
  6. }  

3. 利用class來定義,為要禁用的input增加一個class
 

CSS Code復(fù)制內(nèi)容到剪貼板
  1. input.disabled{   
  2.     border1px solid #DDD;   
  3.     background-color#F5F5F5;   
  4.     color:#ACA899;   
  5. }  

最終結(jié)果:
 

CSS Code復(fù)制內(nèi)容到剪貼板
  1. //Chrome Firefox Opera Safari IE9+   
  2. input:disabled{   
  3.     border1px solid #DDD;   
  4.     background-color#F5F5F5;   
  5.     color:#ACA899;   
  6. }   
  7. //IE8-   
  8. input[disabled]{   
  9.     border1px solid #DDD;   
  10.     background-color#F5F5F5;   
  11.     color:#ACA899;   
  12. }   
  13. //IE6 Using Javascript to add CSS class "disabled"  
  14. * html input.disabled{   
  15.     border1px solid #DDD;   
  16.     background-color#F5F5F5;   
  17.     color:#ACA899;   
  18. }  

注意:IE8 bug
由于IE8 不識別 :disabled 導(dǎo)致input[disabled],input:disabled樣式失效,可以考慮單獨(dú)來寫,或者直接使用input[disabled]。;IE9及以下無法改變字體顏色。

    Demo

相關(guān)文章

最新評論