JQuery中几个类选择器的简单使用介绍
jQuery 使用 简单 介绍 几个 选择器
2023-06-13 09:14:47 时间
<%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="TestClassSelector.aspx.cs"Inherits="WebApplication1.TestClassSelector"%>
<!DOCTYPEhtml>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
<scriptsrc="Scripts/jquery-1.9.0.min.js"></script>
<styletype="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>
<formid="form1"runat="server">
<div>
<divclass="first_div">
Thisisthefirstdiv
</div>
<divclass="second_div">
Thisistheseconddiv
</div>
<divclass="first_div">
<spanclass="first_span">
Thisisthefirstspan
</span>
</div>
<spanclass="first_spaneric_sun_class">
Thisisthefirstspan+ericsunclass.
</span>
<br/>
<spanclass="eric_sun_class">
Thisistheericsunclass.
</span>
<br/>
<inputtype="button"value="Test"onclick="btn_Click();"/>
</div>
</form>
</body>
</html>
<scripttype="text/javascript">
functionbtn_Click(){
alert($(".first_div").text());
alert($(".first_div.first_span").text());
}
</script>
$(".first_div,.first_span")
将包含有.first_div或者.first_span"的对象都取到。这里取到4个对象。
此处的Html对应
<divclass="first_div">
Thisisthefirstdiv
</div>
<divclass="first_div">
<spanclass="first_span">
Thisisthefirstspan
</span>
</div>
<spanclass="first_spaneric_sun_class">
Thisisthefirstspan+ericsunclass.
</span>
$(".first_div.first_span")
将以.first_div为类的控件下的以.first_span为类的对象取到(类与类之间带有空格逐层取)。这里只取到1个。
对应的className="first_span"此处的Html对应
<divclass="first_div">
<spanclass="first_span">
Thisisthefirstspan
</span>
</div>
$(".first_span.eric_sun_class")
将包含有.first_span并且同时包含有.eric_sun_class类的对象取到(类与类之间没有空格类似于‘与"操作)。这里只取到1个。
对应的className="first_spaneric_sun_class"此处的Html对应
<spanclass="first_spaneric_sun_class">
Thisisthefirstspan+ericsunclass.
</span>
相关文章
- JQuery插件模板制作jquery插件的朋友可以参考下
- jquery.validate使用攻略第三部
- jquery的extend和fn.extend的使用说明
- JQuery中判断一个元素下面是否有内容或者有某个标签的判断代码
- jquery之$().hover(func1,funct2)使用方法
- php中jQuery插件autocomplate的简单使用笔记
- Jquery瀑布流插件使用介绍
- IE6下opacity与JQuery的奇妙结合
- jQuery实用基础超详细介绍
- jQuery使用技巧简单汇总
- jQuery使用一个按钮控制图片的伸缩实现思路
- jquery子元素过滤选择器使用示例
- jquery.qrcode在线生成二维码使用示例
- jquery鼠标停止移动事件
- jQuery简单图表peity.js使用示例
- jQuery浏览器CSS3特写兼容实例
- jquery实现搜索框常见效果的方法
- jQuery中$.each使用详解
- jquery学习总结(超级详细)
- 使用jsdom和jquery分别实现简单增删改