<input class="problem" type="text" value="some text" disabled="disabled">
如何更改「某些文本」的顏色?更改輸入值的顏色
upd:通過CSS的樣式只能在Chrome中工作& Mozilla。我需要支持所有瀏覽器,包括IE7 +
<input class="problem" type="text" value="some text" disabled="disabled">
如何更改「某些文本」的顏色?更改輸入值的顏色
upd:通過CSS的樣式只能在Chrome中工作& Mozilla。我需要支持所有瀏覽器,包括IE7 +
對於跨瀏覽器解決方案,你需要使用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">
只是應用一些CSS風格,例如
.problem {
color : red;
}
你甚至可以爲正常和禁用的輸入定義兩種不同的顏色,例如:
.problem { color : red; }
.problem[disabled] { color : #cfcfcf; }
例如小提琴:http://jsfiddle.net/dgNZS
在舊版本的IE是不可能改變的殘疾輸入元素的顏色已經answered here,但你可以嘗試按照bobince的解決方法。
它只適用於Chrome和Mozilla –
http://jsfiddle.net/dgNZS/這工作正常也Fx12,Safari和歌劇 – fcalderan
我只是刪除殘疾=「禁用」。 Thx –
給它一個風格即style="color:green"
<input class="problem" type="text" value="some text" disabled="disabled" style="color:green">
或包含此在你的類,你給輸入。
它只適用於Chrome和Mozilla –
演示http://jsfiddle.net/ELuXW/1/
API:CSS - http://api.jquery.com/css/
這應有助於,:)
代碼
$('.problem').css('color', 'blue');
你可以改變文本框的禁用風格在所有瀏覽器所有屬性,除了文本的顏色,只在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。
使用CSS是simle:'color:#ff0000;'將會是紅色 – antyrat
簽出style =「color:green」或任何顏色都適用於所有瀏覽器 –
只需添加樣式,如答案中所示。但只有一個問題,Opera在禁用時不會着色。 –