admin管理员组文章数量:1332889
<input class="problem" type="text" value="some text" disabled="disabled">
How can i change color of "some text"?
upd: Styling by CSS working only in Chrome & Mozilla. I need support of all browser including IE7+
<input class="problem" type="text" value="some text" disabled="disabled">
How can i change color of "some text"?
upd: Styling by CSS working only in Chrome & Mozilla. I need support of all browser including IE7+
Share Improve this question edited Jul 4, 2012 at 11:34 gotbahn asked Jul 4, 2012 at 11:28 gotbahngotbahn 5162 gold badges4 silver badges19 bronze badges 3-
using CSS is simle:
color:#ff0000;
will be red – antyrat Commented Jul 4, 2012 at 11:29 - Checkout the style="color:green" or any color would work in all browsers – Shiv Kumar Ganesh Commented Jul 4, 2012 at 11:32
- Just add style, as show in the answers. Only one problem though, Opera doesn't color it when disabled. – Deep Frozen Commented Jul 4, 2012 at 11:32
5 Answers
Reset to default 3just apply some css style, e.g.
.problem {
color : red;
}
you can even define two different colours for both normal and disabled inputs like so;
.problem { color : red; }
.problem[disabled] { color : #cfcfcf; }
example fiddle: http://jsfiddle/dgNZS
On older IE versions is not possible change the colour of a disabled input element as already answered here but you can try to follow bobince's workaround.
You can change the disable style of the textbox for all properties in all browsers, except the color of the text and only in the IE. For IE (for all properties except the text color) you must set the doctype to 4.01 strict, and then using the code like
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3/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>
But if you use the readonly instead of disabled="disabled" like Engineer wrote this works also in the ie.
For cross-browser solution, you need to use readonly
and unselectable
attributes instead of disabled
, and apply these styles:
.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;
/**/
}
markup:
<input class="problem" type="text" value="some text" readonly unselectable="on">
DEMO
Give it a Style ie style="color:green"
<input class="problem" type="text" value="some text" disabled="disabled" style="color:green">
Or Include this in your class you give to input.
Demo http://jsfiddle/ELuXW/1/
API: CSS - http://api.jquery./css/
This should help, :)
code
$('.problem').css('color', 'blue');
本文标签: javascriptChange color of value in inputStack Overflow
版权声明:本文标题:javascript - Change color of value in input - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742315257a2451685.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论