jquery中addClass()、removeClass()、Css()

来源:互联网 发布:荣威e550网络连接 编辑:程序博客网 时间:2024/05/20 00:11
1、jQuery中addClass方法用来为节点添加样式
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
.important{
font-weight:bold;
font-size:xx-large;
}
.blue{
color:blue;
}
</style>
<script type="text/javascript" src="js/jquery-1.8.0.js"></script>
<script type="text/javascript">
$(function(){
$("#btn").dblclick(function(){
$("h1,h2,p").addClass("blue");
$("div").addClass("important");
});
});
</script>
</head>
<body>
<h1>标题 1</h1>
<h2>标题 2</h2>
<p>这是一个段落。</p>
<p>这是另一个段落。</p>
<div>这是非常重要的文本!</div>
<br>
<input id="btn" type="button" value="addClass" />
</body>
</html>
同时,addClass同样支持添加多种属性
如:$("#div1").addClass("important blue");
2、删除class属性:
removeClass()
$("h1,h2,p").removeClass(“blue”)
3、为某个节点添加样式css()
 $("p").css("background-color","yellow");
4、为节点添加一系列样式css()
$("p").css({"font-size":"xx-large","background-color":"yellow"});
阅读全文
0 0
原创粉丝点击