模拟实现disabled属性
<html>
<head>
<title>disabled设置字体颜色</title>
</head>
<script>
function init(){
readOnlySelect(document.getElementById("readOnlyResType"));
}
function readOnlySelect(obj){
obj.onfocus = function(){
return this.blur();
}
obj.onmouseover = function(){
return this.setCapture();
}
obj.onmouseout = function(){
return this.releaseCapture();
}
}
</script>
<body onload='init()'>
<input type="text" readonly style="color:#FF0000" value="红色" />
<input type="text" disabled style="color:#FF0000" value="红色" />
<span id="readOnlyResType">
<select style="color:#FF0000">
<option>红色</option>
<option>红色</option>
</select>
</body>
</html>
用readOnly后按Backspace键会执行到上一步。可以通过js禁止
function document.onkeydown() { if (event.keyCode == 8) { //alert(document.activeElement.type); if (document.activeElement.type.toLowerCase() == "textarea" || document.activeElement.type.toLowerCase() == "text") { if (document.activeElement.readOnly == false) return true; } return false; } }