DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> CSS入門知識 >> CSS詳解 >> CSS的expression判斷表達式設置input樣式
CSS的expression判斷表達式設置input樣式
編輯:CSS詳解     
用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>
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved