当前位置: 首页 > 图文教程 > 网页制作 > CSS样式表 > CSS的expression判断表达式设置input样式

CSS样式表
css position: absolute、relative详解
实用CSS 文字收集
CSS之少用继承,多用组合
IE下href 的 BUG问题
firefox的超链接点击去除扩大的难看虚线的解决方法
css li 超出隐藏代码
多浏览器支持CSS 容器内容超出(溢出)支持自动换行
IE6不能正常解析CSS文件问题的解决方法及原因分析
css 表单效果
div+css模拟表格效果代码
ie6 注释引起的问题
CSS Hack 汇总快查
CSS小例子(只显示下划线的文本框,像文字一样的按钮)
另一个角度谈谈DIV+CSS
单行图片文字垂直居中问题:实战
符合标准的div+css制作的弹出菜单
DIV+CSS常见错误汇总
基本的页面设计元素布局比例
CSS学习者:2008年不要作浮躁的人
关于学习DIV+CSS的一些精妙问答

CSS样式表 中的 CSS的expression判断表达式设置input样式


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-28   浏览: 103 ::
收藏到网摘: n/a

  用CSS的expression判断表达式设置input样式,简单,轻量级。缺点在于expression判断表达式FireFox是不支持的。致命的是只能区分出一个(例如例子中就只能区分出text文本框),不要试图设置多个…

  代码:

<!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>