CSS expression判断表达式设置input样式
2009-06-14 23:52
435 查看
用CSS的expression判断表达式设置input样式,简单,轻量级。缺点在于expression判断表达式FireFox是不支持的。致命的是只能区分出一个(例如例子中就只能区分出text文本框),不要试图设置多个…
代码:
另一种方法:
1、将 input 的属性取出来,赋给 className。
2、对于 expression,这里使用一个无关紧要的属性(此处是zoom)来触发,处理完需要做的事情之后,再将此属性覆盖掉以解决 expression 不断执行的效率问题。
代码:
代码:
<!doctype html public "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>www.52CSS.com</title> <meta name="Author" content="JustinYoung"/> <meta name="Keywords" content=""/> <meta name="Description" content=""/> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <style type="text/css"> input { background-color:expression(this.type=="text"?'#FFC':''); } </style> </head> <body> <dl> <dt>This is normal textbox:<dd><input type="text" name=""> <dt>This is normal button:<dd><input type="button" value="i'm button"> </dl> </body> </html>
另一种方法:
input{ zoom: expression(function(ele){(ele.className)?ele.className+=" "+ele.type:ele.className=ele.type; ele.style.zoom = "1";}(this)); }
1、将 input 的属性取出来,赋给 className。
2、对于 expression,这里使用一个无关紧要的属性(此处是zoom)来触发,处理完需要做的事情之后,再将此属性覆盖掉以解决 expression 不断执行的效率问题。
代码:
<!--[if lt IE 7]>
<style type="text/css" media="screen">input{ zoom: expression(function(ele){(ele.className)?ele.className+=" "+ele.type:ele.className=ele.type; ele.style.zoom = "1";}(this)); }input.text{
border: 1px solid; border-color: #CCC #EEE #EEE #CCC;
background: #F5F5F5;
}
input.password{
border: 1px solid; border-color: #CCC #EEE #EEE #CCC;
color: #000; background: #F5F5F5;
width: 50px;
}
input.button{
border: 1px solid; border-color: #EEE #CCC #CCC #EEE;
color: #000; font-weight: bold; background: #F5F5F5;
}
input.reset{
border: 1px solid; border-color: #EEE #CCC #CCC #EEE;
color: #666; background: #F5F5F5;
}
</style>
<![endif]-->
<style type="text/css" media="all">
input[type="text"]{
border: 1px solid; border-color: #CCC #EEE #EEE #CCC;
background: #F5F5F5;
}
input[type="password"]{
border: 1px solid; border-color: #CCC #EEE #EEE #CCC;
color: #000; background: #F5F5F5;
width: 50px;
}
input[type="button"]{
border: 1px solid; border-color: #EEE #CCC #CCC #EEE;
color: #000; font-weight: bold; background: #F5F5F5;
}
input[type="reset"]{
border: 1px solid; border-color: #EEE #CCC #CCC #EEE;
color: #666; background: #F5F5F5;
}
</style>
</head>
<body>
<input type="text" name="xx" />
<input type="password" name="yy" />
<input type="checkbox" name="oo" />
<input type="radio" name="pp" />
<input type="button" name="qq" value="button" />
<input type="reset" name="oo" value="reset" />
</body>
</html>
相关文章推荐
- CSS的expression判断表达式设置input样式
- CSS分别设置Input样式(按input类型
- TextInputLayout 样式设置
- 设置input透明背景及placeholder样式
- 【转载】给不同 type 的 input 自动设置样式
- (转载)CSS分别设置Input样式(按input类型)
- 设置<input type="file">的默认样式
- 设置input file的样式
- CSS分别设置Input样式(按input类型)
- 设置样式时怎么区分input是按钮还是文本框
- 设置input 的 checkbox样式
- js无法获取未设置样式的input的宽高
- Flex Gumbo中如何通过contentBackgroundColor样式,设置TextInput内文本背景颜色
- 关于input的placeholder的样式设置问题,兼容多种浏览器
- 2015.7.22 第十一课 课程重点(jq:元素获取、添加、删除、过滤、判断、遍历、取值,样式设置、改变对象、切换、判断)
- 设置input获得焦点边框样式
- input type=range样式设置,分别设置左右颜色,增大点击有效范围
- jsp 设置自己喜欢的input:file样式
- CSS分别设置Input样式(按input类型)
- input file样式设置