input禁用样式修改 input disabled样式禁用方法及样式isabled样式禁用方法及样式

disabled 属性规定应该禁用 input 元素。
被禁用的 input 元素既不可用,也不可点击。可以设置 disabled 属性,直到满足某些其他的条件为止(比如选择了一个复选框等等)。然后,就需要通过 JavaScript 来删除 disabled 值,将 input 元素的值切换为可用。
input-disabled
以下三种写法都可以禁用 input

1
2
3
< input type = "text" disabled = "disabled" value = "已禁用" />
< input type = "text" disabled = "disabled" value = "已禁用" />
< input type = "text" disabled = "disabled" value = "已禁用" />

被禁用的 input 默认显示灰色,可以通过CSS修改样式。注:IE9及以下无法改变字体颜色

1. 利用CSS3 :disabled 伪元素定义

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

2. 利用属性选择符定义

1
2
3
4
5
6
//IE 6 failed
input[disabled]{
     border : 1px solid #DDD ;
     background-color : #F5F5F5 ;
     color : #ACA899 ;
}

3. 利用class来定义,为要禁用的input增加一个class

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

最终结果:

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
//Chrome Firefox Opera Safari IE 9 +
input:disabled{
     border : 1px solid #DDD ;
     background-color : #F5F5F5 ;
     color : #ACA899 ;
}
//IE 8 -
input[disabled]{
     border : 1px solid #DDD ;
     background-color : #F5F5F5 ;
     color : #ACA899 ;
}
//IE 6 Using Javascript to add CSS class "disabled"
* html input.disabled{
     border : 1px solid #DDD ;
     background-color : #F5F5F5 ;
     color : #ACA899 ;
}

注意:IE8 bug
由于IE8 不识别 :disabled 导致input[disabled],input:disabled样式失效,可以考虑单独来写,或者直接使用input[disabled]。;IE9及以下无法改变字体颜色。

Demo

 

转载于:https://www.cnblogs.com/shimily/articles/9633759.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值