摘要:代码如下:<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestClassSelector.aspx.cs" Inherits="WebApplication1.TestClassSelector" %> <!DOCTYPE html> <html xmlns="https://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_p { background-color:red; } .second_p { 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"> <p> <p class="first_p"> This is the first p </p> <p class="second_p"> This is the second p </p> <p class="first_p"> <span class="first_span"> This is the first span </span> </p> <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();" /> </p> </form> </body> </html> <script type="text/javascript"> function btn_Click() { alert($(".first_p").text()); alert($(".first_p.first_span").text()); } </script>

小宝典致力于为广大程序猿(媛)提供高品质的代码服务,请大家多多光顾小站,小宝典在此谢过。

代码如下:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestClassSelector.aspx.cs" Inherits="WebApplication1.TestClassSelector" %>
<!DOCTYPE html>
<html xmlns="https://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_p {
background-color:red;
}
.second_p {
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">
<p>
<p class="first_p">
This is the first p
</p>
<p class="second_p">
This is the second p
</p>
<p class="first_p">
<span class="first_span">
This is the first span
</span>
</p>
<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();" />
</p>
</form>
</body>
</html>
<script type="text/javascript">
function btn_Click() {
alert($(".first_p").text());
alert($(".first_p.first_span").text());
}
</script>

. 代码如下:

$(".first_p, .first_span")

将包含有.first_p 或者 .first_span" 的对象都取到。 这里取到 4 个 对象。
此处的Html对应

. 代码如下:

<p class="first_p">
This is the first p
</p>
<p class="first_p">
<span class="first_span">
This is the first span
</span>
</p>
<span class="first_span eric_sun_class">
This is the first span + eric sun class.
</span>

. 代码如下:

$(".first_p .first_span")

将以 .first_p 为类的控件 下的 以 .first_span 为类 的对象取到(类与类之间带有空格 逐层取)。 这里只取到 1 个。
对应的 className="first_span" 此处的Html对应

. 代码如下:

<p class="first_p">
<span class="first_span">
This is the first span
</span>
</p>

. 代码如下:

$(".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>

代码如下:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestClassSelector.aspx.cs" Inherits="WebApplication1.TestClassSelector" %>
<!DOCTYPE html>
<html xmlns="https://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_p {
background-color:red;
}
.second_p {
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">
<p>
<p class="first_p">
This is the first p
</p>
<p class="second_p">
This is the second p
</p>
<p class="first_p">
<span class="first_span">
This is the first span
</span>
</p>
<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();" />
</p>
</form>
</body>
</html>
<script type="text/javascript">
function btn_Click() {
alert($(".first_p").text());
alert($(".first_p.first_span").text());
}
</script>

. 代码如下:

$(".first_p, .first_span")

将包含有.first_p 或者 .first_span" 的对象都取到。 这里取到 4 个 对象。
此处的Html对应

. 代码如下:

<p class="first_p">
This is the first p
</p>
<p class="first_p">
<span class="first_span">
This is the first span
</span>
</p>
<span class="first_span eric_sun_class">
This is the first span + eric sun class.
</span>

. 代码如下:

$(".first_p .first_span")

将以 .first_p 为类的控件 下的 以 .first_span 为类 的对象取到(类与类之间带有空格 逐层取)。 这里只取到 1 个。
对应的 className="first_span" 此处的Html对应

. 代码如下:

<p class="first_p">
<span class="first_span">
This is the first span
</span>
</p>

. 代码如下:

$(".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>

觉得可用,就经常来吧!Javascript技巧 脚本宝典 欢迎评论哦! js技巧,巧夺天工,精雕玉琢。小宝典献丑了!

本文固定链接: http://www.js-code.com/js/js_1211.html