国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
css統(tǒng)一設(shè)置input樣式(區(qū)分input類型
css統(tǒng)一設(shè)置input樣式(區(qū)分input類型)
2009-04-20 15:38

當(dāng)你看到<input>這個html標(biāo)簽的時候,你會想到什么?一個文本框?一個按鈕?一個單選框?一個復(fù)選框?……對,對,對,它們都對。也許你可能想不到,這個小小的input竟然可以創(chuàng)造出10個不同的東西,下面是個列表,看看,哪些是你沒有想到的:

<input type="text" /> 文本框
<input type="password" /> 密碼框
<input type="submit" /> 提交按鈕
<input type="reset" /> 重置按鈕
<input type="radio" /> 單選框
<input type="checkbox" /> 復(fù)選框
<input type="button" /> 普通按鈕
<input type="file" /> 文件選擇控件
<input type="hidden" /> 隱藏框
<input type="image" /> 圖片按鈕

所以你可能會說,input真是一個偉大的東西,竟然這么有“搞頭”,但是當(dāng)你真正在項目中試圖給不同的控件設(shè)置不同的樣式時,你就會發(fā)現(xiàn),input真的可以把“你的頭搞大”。我不知道為什么當(dāng)初要給input賦予那么多身份,但是,他的“N重身份”給網(wǎng)站設(shè)計者的確帶來了不少的麻煩。好在,勞動人民是偉大的,解決問題的辦法還是有滴~,雖然它們都有各自致命的缺點 Orz… 解放方法大致歸納一下,列表如下(小弟才疏,錯誤遺漏難免,還請各位高人指點):

1.用css的expression判斷表達(dá)式

2.用css中的type選擇器

3.用javascript腳本實現(xiàn)

4.如果你用Microsoft Visual Studio 2005 或者后續(xù)版本開發(fā)項目,恭喜,你還可以使用skin。

下面就來講解一下各個辦法的詳細(xì)實現(xiàn)和它們的優(yōu)缺點。

1:用css的expression判斷表達(dá)式

實現(xiàn)代碼參考:

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

優(yōu)點:簡單,輕量級

缺點:expression判斷表達(dá)式FireFox是不支持的。致命的是只能區(qū)分出一個(例如例子中就只能區(qū)分出text文本框),不要試圖設(shè)置多個,下面的會將上面的覆蓋掉 Orz…

★★★★★★★★★★★★★★★★★★★★★★★★★★★

另一種方法:

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,這里使用一個無關(guān)緊要的屬性(此處是zoom)來觸發(fā),處理完需要做的事情之后,再將此屬性覆蓋掉以解決 expression 不斷執(zhí)行的效率問題。


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

 

★★★★★★★★★★★★★★★★★★★★★★★★★★★

 

2:用css中的type選擇器

實現(xiàn)參考代碼:

<!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> diffInput2 </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[type="text"]

    {

    background-color:#FFC;

    }

   

    input[type="password"]

    {

    background-image:url(BG.gif);

    }

   

    input[type="submit"]

    {

    background-color:blue;

    color:white;

    }

   

    input[type="reset"]

    {

    background-color:navy;

    color:white;

    }

   

   input[type="radio"]

    {

    /*In FF,Some radio style like background-color not been supported*/

    margin:10px;

    }

   

    input[type="checkbox"]

    {

    /*In FF,Some checkbox style like background-color not been supported*/

    margin:10px;

    }

   

    input[type="button"]

    {

    background-color:lightblue;

    }

    </style>

</head>

<body>

<dl>

<dt>This is normal textbox:<dd><input type="text" name="">

<dt>This is password textbox:<dd><input type="password" name="">

<dt>This is submit button:<dd><input type="submit">

<dt>This is reset button:<dd><input type="reset">

<dt>This is radio:<dd><input type="radio" name="ground1"> <input type="radio" name="ground1">

<dt>This is checkbox:<dd><input type="checkbox" name="ground2"> <input type="checkbox" name="ground2">

<dt>This is normal button:<dd><input type="button" value="i'm button">

</dl>

</body>

</html>

優(yōu)點:簡單,明了,可以分區(qū)出各個input控件形態(tài)。

缺點:type選擇器,IE6之前的對web標(biāo)準(zhǔn)支持的不太好的瀏覽器不能支持(致命呀 Orz…)

 

3:用javascript腳本實現(xiàn)

實現(xiàn)參考代碼:

前臺html代碼:

<!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> diffInput </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{behavior:url('css.htc');}

    </style>

</head>

<body>

<dl>

<dt>This is normal textbox:<dd><input type="text" name="">

<dt>This is password textbox:<dd><input type="password" name="">

<dt>This is submit button:<dd><input type="submit">

<dt>This is reset button:<dd><input type="reset">

<dt>This is radio:<dd><input type="radio" name="ground1"> <input type="radio" name="ground1">

<dt>This is checkbox:<dd><input type="checkbox" name="ground2"> <input type="checkbox" name="ground2">

<dt>This is normal button:<dd><input type="button" value="i'm button">

</dl>

</body>

</html>

Css.htc代碼:

<script language=javascript>

switch(type)

{

    case 'text':

    style.backgroundColor="red";

    break;

    case 'password':

    style.backgroundImage="url(BG.gif)";

    break;

    case 'submit':

    style.backgroundColor="blue";

    style.color="white";

    break;

    case 'reset':

    style.backgroundColor="navy";

    style.color="white";

    break;

    case 'radio':

    style.backgroundColor="hotpink";

    break;

    case 'checkbox':

    style.backgroundColor="green";

    break;

    case 'button':

    style.backgroundColor="lightblue";

    break;

    default: ;//others use default style.

}

</script>

優(yōu)點:可以分區(qū)出各個input控件形態(tài)。多種技術(shù)的混合使用,滿足“我是高手”的虛榮心。

缺點:技術(shù)牽扯面教廣,因為用js后期處理,所以在js沒有起作用之前,各個input還是原始狀態(tài),然后突然“變帥”會讓你的頁面很奇怪。較致命的是FireFox不支持 Orz…

4:Microsoft Visual Studio 2005中使用skin。

Skin文件參考代碼:

<%--Style for common TextBox--%>

<asp:TextBox runat="server" style="background-color:#FFC "></asp:TextBox>

<asp:Button runat="server" style=”background-color:red”></asp:Button>


注意里面的樣式是用style加上的,而不是用cssClass,道理很簡單,如果用cssClass,前面的再用cssClass就會覆蓋這個cssClass。導(dǎo)致失敗。當(dāng)然,skin不能單獨使用,還要配合css樣式表。

優(yōu)點:可以分區(qū)出各個控件形態(tài)(注意:skin只能對服務(wù)器端控件使用,所以現(xiàn)在已經(jīng)不是單純的input標(biāo)簽了,雖然這些服務(wù)器端控件“打到”前臺的時候仍然是input控件)。除了css,又被分離一層,使得樣式的設(shè)置能有更好的定制性。其他優(yōu)點(參考skin的優(yōu)點)。

缺點:只能對服務(wù)器端控件使用。不是所有的項目都能使用skin功能 Orz…

本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
子元素過濾器練習(xí)頁
css樣式之區(qū)分input是按鈕還是文本框的方法
css的簡介
HTML進(jìn)階應(yīng)用技巧(十)用好表單的按鈕
返回主頁 SUPERMAN-代碼收集狂css小貼士備忘錄
HTML
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服