DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> jQuery入門知識 >> JQuery特效代碼 >> JQuery 中幾個類選擇器的簡單使用介紹
JQuery 中幾個類選擇器的簡單使用介紹
編輯:JQuery特效代碼     
. 代碼如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestClassSelector.aspx.cs" Inherits="WebApplication1.TestClassSelector" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="Scripts/jquery-1.9.0.min.js"></script>
<style type="text/css">
.first_div {
background-color:red;
}
.second_div {
background-color:green;
}
.first_span {
width:500px;
height:100px;
}
.eric_sun_class {
font-family:Arial;
font-size:18px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<div class="first_div">
This is the first div
</div>
<div class="second_div">
This is the second div
</div>
<div class="first_div">
<span class="first_span">
This is the first span
</span>
</div>
<span class="first_span eric_sun_class">
This is the first span + eric sun class.
</span>
<br />
<span class="eric_sun_class">
This is the eric sun class.
</span>
<br />
<input type="button" value="Test" onclick="btn_Click();" />
</div>
</form>
</body>
</html>
<script type="text/javascript">
function btn_Click() {
alert($(".first_div").text());
alert($(".first_div.first_span").text());
}
</script>

. 代碼如下:
$(".first_div, .first_span")

將包含有.first_div 或者 .first_span" 的對象都取到。 這裡取到 4 個 對象。
此處的Html對應
. 代碼如下:
<div class="first_div">
This is the first div
</div>
<div class="first_div">
<span class="first_span">
This is the first span
</span>
</div>
<span class="first_span eric_sun_class">
This is the first span + eric sun class.
</span>

. 代碼如下:
$(".first_div .first_span")

將以 .first_div 為類的控件 下的 以 .first_span 為類 的對象取到(類與類之間帶有空格 逐層取)。 這裡只取到 1 個。
對應的 className="first_span" 此處的Html對應
. 代碼如下:
<div class="first_div">
<span class="first_span">
This is the first span
</span>
</div>

. 代碼如下:
$(".first_span.eric_sun_class")

將包含有.first_span 並且同時包含有 .eric_sun_class 類的 對象取到(類與類之間沒有空格 類似於 ‘與' 操作)。 這裡只取到1個。
對應的 className="first_span eric_sun_class" 此處的Html 對應
. 代碼如下:
<span class="first_span eric_sun_class">
This is the first span + eric sun class.
</span>
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved