国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

JQuery 中幾個類選擇器的簡單使用介紹

2024-05-06 14:19:18
字體:
供稿:網(wǎng)友
代碼如下:
<%@ 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對應(yīng)
代碼如下:
<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 個。
對應(yīng)的 className="first_span" 此處的Html對應(yīng)
代碼如下:
<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個。
對應(yīng)的 className="first_span eric_sun_class" 此處的Html 對應(yīng)
代碼如下:
<span class="first_span eric_sun_class">
This is the first span + eric sun class.
</span>
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 肥城市| 松桃| 乐安县| 桐城市| 余干县| 丹东市| 郎溪县| 遂宁市| 尼木县| 库车县| 临沂市| 察隅县| 商洛市| 白银市| 宾川县| 响水县| 左权县| 顺昌县| 磐安县| 海城市| 明光市| 苏尼特左旗| 城口县| 乌鲁木齐市| 定西市| 宜兰县| 牙克石市| 札达县| 永平县| 高密市| 新河县| 丹巴县| 泸州市| 贺州市| 凌源市| 扬州市| 乌什县| 麟游县| 同德县| 潢川县| 嵩明县|