`
llmy
  • 浏览: 119683 次
  • 性别: Icon_minigender_2
  • 来自: 济南
社区版块
存档分类
最新评论

文本框及下拉框设置disabled后,改变字体的颜色

阅读更多

模拟实现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;
        }
    }

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics