作家
登录

JQuery 中几个类选择器的简单使用介绍

作者: 来源:www.28hudong.com 2013-03-30 00:07:57 阅读 我要评论

复制代码 代码如下: <%@ 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>

  推荐阅读

  JS实现悬浮移动窗口(悬浮广告)的特效

js方法: 复制代码 代码如下:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title> New Document </title> <meta na>>>详细阅读


本文标题:JQuery 中几个类选择器的简单使用介绍

地址:http://www.17bianji.com/kaifa2/JS/22212.html

关键词: 探索发现

乐购科技部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与乐购科技进行文章共享合作。

网友点评
自媒体专栏

评论

热度

精彩导读
栏目ID=71的表不存在(操作类型=0)