国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

jQuery - 取得並設(shè)定 CSS 類(lèi)

jQuery 運(yùn)算 CSS

jQuery 擁有若干進(jìn)行 CSS 運(yùn)算的方法。我們將學(xué)習(xí)下面這些:

addClass() - 將一個(gè)或多個(gè)類(lèi)別新增一個(gè)類(lèi)別

#removeClass() - 從被選元素中刪除一個(gè)或多個(gè)類(lèi)別

toggleClass() - 被選取元素進(jìn)行新增/刪除類(lèi)別的切換操作

css() - 設(shè)定或傳回樣式屬性

樣式表

.important ?

{

#font-weight:bold;


################################################################# #font-size:xx-large;############}##########


addClass() 方法

#
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("h1,h2,p").addClass("blue");
    $("div").addClass("important");
  });
});
</script>
<style type="text/css">
.important
{
font-weight:bold;
font-size:xx-large;
}
.blue
{
color:blue;
}
</style>
</head>
<body>
<h1>標(biāo)題 1</h1>
<h2>標(biāo)題 2</h2>
<p>段落1</p>
<p>段落2</p>
<div>文本</div>
<br>
<button>為元素添加 class</button>
</body>
</html>

也可以在addClass() 方法中規(guī)定多個(gè)類(lèi):

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("#div1").addClass("important blue");
  });
});
</script>
<style type="text/css">
.important
{
font-weight:bold;
font-size:xx-large;
}
.blue
{
color:blue;
}
</style>
</head>
<body>
<div id="div1">文本。</div>
<div id="div2">文本。</div>
<br>
<button>為第一個(gè)元素添加類(lèi)</button>
</body>
</html>


removeClass() 方法

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("h1,h2,p").removeClass("blue");
  });
});
</script>
<style type="text/css">
.important
{
font-weight:bold;
font-size:xx-large;
}
.blue
{
color:blue;
}
</style>
</head>
<body>
<h1 class="blue">標(biāo)題 1</h1>
<h2 class="blue">標(biāo)題 2</h2>
<p class="blue">段落1</p>
<p>段落2</p>
<br>
<button>從元素中移除 class</button>
</body>
</html>


toggleClass() 方法

#該方法對(duì)被選元素進(jìn)行新增/刪除類(lèi)別的切換操作:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("h1,h2,p").toggleClass("blue");
  });
});
</script>
<style type="text/css">
.blue
{
color:blue;
}
</style>
</head>
<body>
<h1 class="blue">標(biāo)題 1</h1>
<h2 class="blue">標(biāo)題 2</h2>
<p class="blue">段落1</p>
<p>段落2</p>
<br>
<button>切換 class</button>
</body>
</html>


繼續(xù)學(xué)習(xí)
||
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("#btn").click(function(){ $("div").addClass("border reset"); }) }) </script> <style type="text/css"> div{ height:100px; width:200px; } .border{ border:2px solid blue; } .reset{ font-size:20px; color:green; } </style> </head> <body> <div>php.cn歡迎您</div> <button id="btn">點(diǎn)擊查看效果</button> </body> </html>
提交重置程式碼