2012-07-04 88 views
1
<input class="problem" type="text" value="some text" disabled="disabled"> 

如何更改“某些文本”的颜色?更改输入值的颜色

upd:通过CSS的样式只能在Chrome中工作& Mozilla。我需要支持所有浏览器,包括IE7 +

+0

使用CSS是simle:'color:#ff0000;'将会是红色 – antyrat

+0

签出style =“color:green”或任何颜色都适用于所有浏览器 –

+0

只需添加样式,如答案中所示。但只有一个问题,Opera在禁用时不会着色。 –

回答

0

对于跨浏览器解决方案,你需要使用readonly an d unselectable属性,而不是disabled,并应用这些样式:

.problem[readonly]{ 
    color: red; 
    /*Preventing selection*/ 
    -webkit-touch-callout: none; 
    -webkit-user-select: none; 
    -khtml-user-select: none; 
    -moz-user-select: none; 
    -ms-user-select: none; 
    user-select: none; 
    /**/ 
}​ 

标记

<input class="problem" type="text" value="some text" readonly unselectable="on"> 

DEMO

+0

它的工作原理!令人印象深刻,真的。谢谢 –

+0

@Godban我稍微改进了我的答案。再看一遍。 – Engineer

+0

Yeap,看起来不错 –

3

只是应用一些CSS风格,例如

.problem { 
    color : red; 
} 

你甚至可以为正常和禁用的输入定义两种不同的颜色,例如:

.problem { color : red; } 
.problem[disabled] { color : #cfcfcf; } 

例如小提琴:http://jsfiddle.net/dgNZS

在旧版本的IE是不可能改变的残疾输入元素的颜色已经answered here,但你可以尝试按照bobince的解决方法。

+0

它只适用于Chrome和Mozilla –

+0

http://jsfiddle.net/dgNZS/这工作正常也Fx12,Safari和歌剧 – fcalderan

+0

我只是删除残疾=“禁用”。 Thx –

0

给它一个风格即style="color:green"

<input class="problem" type="text" value="some text" disabled="disabled" style="color:green"> 

或包含此在你的类,你给输入。

+0

它只适用于Chrome和Mozilla –

1

你可以改变文本框的禁用风格在所有浏览器所有属性,除了文本的颜色,只在IE中。 对于IE(用于除文本颜色的所有属性),你必须使用像

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 
<html> 
<head> 
<style type="text/css"> 
input[disabled], input[readonly] { 
background-color: green; 
border: #3532ff 1px solid; 
color: #00FF00; 
cursor: default; 
} 
</style> 
</head> 
<body> 
<form> 
<input class="problem" type="text" value="some text" disabled="disabled"> 
</form> 
</body> 
</html> 

代码设置DOCTYPE 4.01严,然后 请大家看看“styling disabled text inputs

但如果你使用只读,而不是disabled =“禁用”工程师写这个作品也在ie。