1
<input class="problem" type="text" value="some text" disabled="disabled">

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

upd:CSS 样式仅适用于 Chrome 和 Mozilla。我需要所有浏览器的支持,包括 IE7+

4

5 回答 5

3

只需应用一些 CSS 样式,例如

.problem {
  color : red;
}

您甚至可以像这样为正常输入和禁用输入定义两种不同的颜色;

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

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

在较旧的 IE 版本上,无法更改已禁用输入元素的颜色,如已在此处回答的,但您可以尝试遵循 bobince 的解决方法。

于 2012-07-04T11:28:59.610 回答
1

您可以更改所有浏览器中所有属性的文本框的禁用样式,文本颜色除外并且仅在 IE 中。对于 IE(对于除文本颜色之外的所有属性),您必须将doctype设置为 4.01 strict,然后使用类似的代码

<!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>

但是,如果您使用readonly而不是disabled="disabled"就像工程师在 ie 中写的那样也可以使用。

于 2012-07-04T12:00:51.460 回答
0

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

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

或者将其包含在您提供输入的课程中。

于 2012-07-04T11:29:51.633 回答
0

演示 http://jsfiddle.net/ELuXW/1/

API:CSS - http://api.jquery.com/css/

这应该有帮助,:)

代码

$('.problem').css('color', 'blue');​
于 2012-07-04T11:29:54.740 回答
0

对于跨浏览器解决方案,您需要使用readonlyunselectable属性而不是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">

演示

于 2012-07-04T11:42:46.117 回答