如何用Jquery区别textbox 和button分别施加不同css呢?

epui2008 2012-03-17 04:44:39
如题,诚心求教

直接input{xxxx...} 会给文本框和按钮 添加一样的css样式

如果分别在元素中 设定 class="" 和 id="" 那就太麻烦了,肯定用jquery 可以区别textbox 和input 吧

请问怎么搞呢?谢谢
...全文
201 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
峭沙 2012-04-27
  • 打赏
  • 举报
回复
你用的是万恶的IE6吧。。
		input{
_background-color: expression((function(elem){
if(elem.type === "text"){
return "#FFFFCC";
}else if(elem.type === "button"){
return "#EEEEEE";
}
})(this));
}
input[type=text]{
background-color: #FFFFCC;
}
input[type=button]{
background-color: #EEEEEE;
}
三石-gary 2012-04-27
  • 打赏
  • 举报
回复
http://haha-net.iteye.com/blog/165132
epui2008 2012-04-27
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 的回复:]

引用 6 楼 yenange 的回复:
引用 4 楼 axiheyhey 的回复:

CSS code
input[type=button]{

}
input[type=text]{

}
CSS轻松就搞定了,哪需要用到什么jQuery。。


顶, 楼主应该这样, 而不是用jquery。

能不写代码的尽量不要写代码。
如果用jquery , 你每个页面都得写……
[/Quote]


这样的css 代码,浏览器识别不了
RainOnly 2012-03-19
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 yenange 的回复:]
引用 4 楼 axiheyhey 的回复:

CSS code
input[type=button]{

}
input[type=text]{

}
CSS轻松就搞定了,哪需要用到什么jQuery。。


顶, 楼主应该这样, 而不是用jquery。

能不写代码的尽量不要写代码。
如果用jquery , 你每个页面都得写, 烦不烦?
[/Quote]

同意 能用css解决的 就不要用js解决
吉普赛的歌 社区高级成员 T9 2012-03-19
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 axiheyhey 的回复:]

CSS code
input[type=button]{

}
input[type=text]{

}
CSS轻松就搞定了,哪需要用到什么jQuery。。
[/Quote]

顶, 楼主应该这样, 而不是用jquery。

能不写代码的尽量不要写代码。
如果用jquery , 你每个页面都得写, 烦不烦?
fxfeng2000 2012-03-19
  • 打赏
  • 举报
回复
$("input:text")
$("input:button")
峭沙 2012-03-19
  • 打赏
  • 举报
回复
input[type=button]{

}
input[type=text]{

}
CSS轻松就搞定了,哪需要用到什么jQuery。。
m540920181 2012-03-17
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 p2227 的回复:]

HTML code
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.1.min.js"></script>

<input type="text"/>
<input type="button"/>

<script language="javascript" type="text/javascript">
$(func……
[/Quote]
就这样的形式,以此类推。
p2227 2012-03-17
  • 打赏
  • 举报
回复
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.1.min.js"></script>

<input type="text"/>
<input type="button"/>

<script language="javascript" type="text/javascript">
$(function(){
$("input[type=text]").css("border-color","red");
$("input[type=button]").css("border-color","blue");
})

</script>
Acesidonu 2012-03-17
  • 打赏
  • 举报
回复
$('input[type=button]').addClass('btnClass');
$('input[type=text]').addClass('txtClass');

87,996

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧