先定义CSS样式:

input:focus, input.focus { background:lime; color:black; }


这样之后 网页中的input被激活时候.也就是你光标点击某个输入框时候.输入框的背景颜色会改变为:black.
这样会让这个输入框更加的被人注意到.
倒霉的是 IE6以及更低版本 不能识别 input的focus这个属性.
所以这里使用js来实现相同的效果.
首先定义了.focus这个样式.
用js来判断浏览器. 当发现是IE的话 就检测鼠标点击 获得当前即或的输入框.然后加载.focus这个样式.
从而到达相同的效果.
js代码如下.可以直接加到head区.


<script type="text/javascript">
window.onload = function(){
var inputs = document.getElementsByTagName("input"), i = inputs.length;
while(i--){
inputs[i].onfocus = function(){
this.className += " focus";
};
inputs[i].onblur = function(){
this.className = this.className.replace(" focus", "");
};
};
};
</script>


令人郁闷的是 我以前怎么就不知道input的这个属性啊?!!!
focus这个东西.最近啃书的时候才发现的.
给个CSS速查手册.方便你,我,他.
Tags: , , ,
本站原创 | 评论(0) | 引用(0) | 阅读(2694)
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]