CSS定义input的type类型样式

 

  1. input { width:expression(this.type=="text"?"200px":"style"); }    

  2. input[type="text"] { width:200px }   

通常定义CSS时,书写input 规定宽度,可以使收集数据的页面显得非常整齐.

但如果表单内包含checkbox时,就需要为它单独定义一个样式,把class="name"与checkbox捆绑,非常麻烦.

有没有一种写法,可以分别定义全站input分别对应type="text",type="submit",type="chekbox"….等等的样式呢?

我看苏沈小雨的样式手册有"INPUT type=buttonINPUT type=fileINPUT type=passwordINPUT type=resetINPUT type=submitINPUT type=text"的应用单,但具体怎么用似乎没说.

有知道的好心人,指导一下吧:)

查到这个写法:input[type=text] ,Firefox有效,但IE不支持,对么?

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><br />     

  2. <html xmlns="http://www.w3.org/1999/xhtml"><br />     

  3. <head><br />     

  4. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> </p>     

  5. <style type="text/css">      

  6. <!– INPUT{ border: 1px solid #D4D0C8; width: 200px; } input[type=text] { background-color: #FFCC33; } input[type=checkbox],input[type=radio] { width: 20px;border: 0px; } –>      

  7. </style>     

  8. <p></head><br />     

  9. <body> </p>     

  10. <form id="form1" name="form1" method="post" action="">     

  11. <input type="text" name="textfield" />     

  12. <input name="radiobutton" type="radio" value="radiobutton" />     

  13. <input type="checkbox" name="checkbox" value="checkbox" />     

  14. </form>     

  15. <p></body><br />     

  16. </html>   

 

提示:您可以先修改部分代码再运行

你是说对应type定义CSS? 这个属性选择符目前IE不支持

<style type="text/css"> input { border:expression(this.type=="text"?"1px solid red":"style"); } input[type="text"] { border:1px solid red; } </style> <input type="text" /> <input type="password" />

提示:您可以先修改部分代码再运行

我是想知道,怎么定义input的样式表,才能让下面这两个东东的宽度等于20px?

<input type="radio" />

<input type="checkbox"  />

而input的其它type比如<input type="text" />的宽度为200px?

当然,下面的写法IE和FF都是支持的,但我嫌它麻烦,想找全局都支持,不需要再特意指定Input样式的办法:

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

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

<title>Untitled Document</title>

<style type="text/css">

<!–

INPUT{ border: 1px solid #D4D0C8; width: 200px; }

input.long { background-color: #FFCC33; }

input.short { width: 20px;border: 0px; }

–>

</style>

</head>

<body>

<form id="form1" name="form1" method="post" action="">

<input type="text" class="long"/>

<input type="radio" class="short" />

<input type="checkbox" class="short" />

</form>

</body>

</html>

提示:您可以先修改部分代码再运行

<style type="text/css">

input { width:20px }

input { width:expression(this.type=="text"?"200px":"style"); }

input[type="text"] { width:200px }

</style>

<input type="radio" />

<input type="checkbox" />

<input type="text" />

提示:您可以先修改部分代码再运行

再问问:)

input {

width:expression(this.type=="checkbox"?"20px":"style");

width:expression(this.type=="radio"?"20px":"style");

}

这两行有没有办法合成一行写?:)

找到了,呵呵.

input {

width: expression((this.type=="checkbox" || this.type=="radio") ?"20px":"style");

}

input的CSS样式,有没有分别对应type=text,submit,chekbox…的写法? 之 behavior

cssfile:

input {

behavior: url(bindbutton.htc);

}

htcfile:

<PUBLIC:COMPONENT lightWeight=true>

<PUBLIC:ATTACH EVENT="oncontentready" ONEVENT="load()" />

<PUBLIC:ATTACH EVENT="onmouseout"  ONEVENT="mouseout()" />

<PUBLIC:ATTACH EVENT="onmouseover"  ONEVENT="mousemove()" />

<PUBLIC:ATTACH EVENT="onmousedown" ONEVENT="mousedown()" />

<PUBLIC:ATTACH EVENT="onmouseup" ONEVENT="mouseup()" />

<PUBLIC:PROPERTY NAME="direction" />

<SCRIPT LANGUAGE="JScript">

function load()

{

if ((element.tagName == ‘INPUT’ && (element.type == ‘button’ || element.type == ’submit’ || element.type == ‘reset’)) || (element.tagName == ‘BUTTON’))

{

element.style['background'] = ‘….’;

}

element.style.border = ((element.type==’checkbox’||element.type==’radio’)?’none’:’1px double #888888′);

}

function setImage(sImg)

{

if (bSet)

{

//element.style['background'] = ‘URL(’+ sImg +’)’;

}

}

function mouseout() { setImage(aNormal[iDir]); try{element.style.MozOpacity=0.8;element.filters.alpha.opacity=80;}catch(e){}}

function mousemove() { setImage(aOver[iDir]); try{element.style.MozOpacity=1;element.filters.alpha.opacity=100;}catch(e){}}

function mousedown() { setImage(aClick[iDir]); }

function mouseup() { setImage(aNormal[iDir]); }

</SCRIPT>

</PUBLIC:COMPONENT>

不常见的input属性

1.ENTER键可以让光标移到下一个输入框

<input ōnkeydown="if(event.keyCode==13)event.keyCode=9" >

2.只能为数字(有闪动)   

<input ōnkeyup="value=value.replace(/[^\d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))">

3.只能为数字(无闪动)

<input style="ime-mode:disabled" ōnkeydown="if(event.keyCode==13)event.keyCode=9" ōnKeyPress="if ((event.keyCode<48 || event.keyCode>57)) event.returnValue=false">

4.屏蔽输入法   

<input type="text" name="url" style="ime-mode:disabled" ōnkeydown="if(event.keyCode==13)event.keyCode=9">

5.只能输入两位小数,三位小数(有闪动)   

<input maxlength=9 ōnkeyup="if(value.match(/^\d{3}$/))value=value.replace(value,parseInt(value/10)) ;value=value.replace(/\.\d*\./g,'.')" ōnKeyPress="if((event.keyCode<48 || event.keyCode>57) && event.keyCode!=46 && event.keyCode!=45 || value.match(/^\d{3}$/) || /\.\d{3}$/.test(value)) {event.returnValue=false}" id=text_kfxe name=text_kfxe>

6.取消按钮按下时的虚线框   

在input里添加属性值 hideFocus 或者 hideFocus=true

7.只读文本框内容        

在input里添加属性值 readonly

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值