论坛首页 Java企业应用论坛

『提问』如何根据input type来设置css?

浏览 19494 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2004-12-14  
cooooooool idea, 把版本退回擦屁股之前,写一个js就搞定了,hoho......

thank you, xiaoyu.
0 请登录后投票
   发表时间:2004-12-14  
呵呵 又学到一个东东叫做 Attribute Selectors

一时技痒, 再给一个实现, 希望不要被认为是 BT

<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> Attribute Selectors </title>
</head>
<style>
input {
    border:dotted 1px blue;
    ie-only:expression(
        this.style.border=(this.type=="submit");?"solid 1px darkred":
                          (this.type=="reset"); ?"solid 1px darkgreen":
                          /*else ...*/          "dotted 1px blue"
    );;
}
input[type="submit"] {
    border:solid 1px darkred;
}
input[type="reset"] {
    border:solid 1px darkgreen;
}
</style>
<body>
    <a  href="http://www.w3.org/TR/REC-CSS2/selector.html#attribute-selectors">
        Attribute Selectors
    </a> and ...
    <p>
	IE simulation
    <input type="text" name="">
    <input type="submit">
    <input type="reset">
</body>
</html>


另外 xiaoyu 兄弟说的办法也是很好, 俺以前用来对付表格奇偶行的不同背景色来着.
0 请登录后投票
   发表时间:2004-12-14  
涨知识啊,涨知识。good good study, day day up.
thank you, glassprogrammer.

google了一下ie这个特有的css expression文档:
http://msdn.microsoft.com/workshop/author/dhtml/overview/recalc.asp

还发现一个用ie这个特性做的一个好玩东东:
http://dotnetjunkies.com/WebLog/fredd/archive/2004/10/23/29486.aspx

偶又google一遍,找到一个os项目:
http://sourceforge.net/projects/ie7/
fix IE 对于css2/3支持不规范的问题






------------
Robbin大哥屏蔽了签名,害得偶只好用人工签名......

EJB的痛恨者
Struts的鄙视者
java.util.*的厌恶者

欢迎大家来海阔天空灌水区, 因为只有在这里, 说话可以不经过大脑.
0 请登录后投票
   发表时间:2004-12-17  
cool~~~ wakaka
0 请登录后投票
   发表时间:2004-12-24  
我觉得只要定义一个默认的input的css样式就ok了吧?
0 请登录后投票
   发表时间:2005-01-13  
xiaoyu 写道
写一个js,用js绑定就可以了:

var inputs=document.getElementByTagName("input");

for(var i=0;i&lt;inputs.length;i++){
      var input=inputs[i];
      
     if("hidden"!=input.type)  input.className=input.type; //当然你可以再细分
}


一个小错误

var inputs = document.getElementsByTagName("input");
0 请登录后投票
   发表时间:2005-03-03  
试过这个方法,不错,但是非常影响速度
glassprogrammer 写道

<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> Attribute Selectors </title>
</head>
<style>
input {
    border:dotted 1px blue;
    ie-only:expression(
        this.style.border=(this.type=="submit");?"solid 1px darkred":
                          (this.type=="reset"); ?"solid 1px darkgreen":
                          /*else ...*/          "dotted 1px blue"
    );;
}
input[type="submit"] {
    border:solid 1px darkred;
}
input[type="reset"] {
    border:solid 1px darkgreen;
}
</style>
<body>
    <a  href="http://www.w3.org/TR/REC-CSS2/selector.html#attribute-selectors">
        Attribute Selectors
    </a> and ...
    <p>
	IE simulation
    <input type="text" name="">
    <input type="submit">
    <input type="reset">
</body>
</html>



还是xiaoyu同学的比较实用
	var inputs=document.getElementsByTagName("input");; 
	for(var i=0;i<inputs.length;i++);{ 
		var input=inputs[i]; 
		if("hidden"!=input.type); input.className=input.type; 
	}
0 请登录后投票
   发表时间:2005-03-03  
补充一下,当时的测试代码是

引用
input {
border-style:expression((this.type=="text")?"solid":"");
    border-width:expression((this.type=="text")?"0px 0px 1px 0px":"");
    background-color:expression((this.type=="submit")?"#F6F6F6":(this.type=="reset")?"#F6F6F6":(this.type=="button")?"#F6F6F6":"");
    padding-top:expression((this.type=="text")?"8px":"");
}


input tag比较多,49个
在P4M 1.4G 512M上比较慢
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics