jQuery_03 筛选&文档处理

本文详细介绍了jQuery中的筛选方法,包括first(), last(), eq(), filter(), has(), not()等,以及如何根据class属性添加样式。此外,还讨论了查找方法,如children(), find(), parent(), parents()等。同时,讲解了文档处理中的增加、删除和修改元素的方法,如append(), prepend(), empty(), remove(), replaceWith()等,最后通过全选案例进行实践应用。" 45016073,4904529,模余排序算法实现,"['算法', '编程', '数据处理']
摘要由CSDN通过智能技术生成

一:筛选中的过滤方法有哪些?

 first()  获取匹配的第一个元素

          <style>
			.cc {
				box-shadow: 0px 0px 50px yellow;
			}

		</style>
		<script>
			$(function() {
				//first() 获取匹配的第一个元素
				console.log($("img").first());
				//添加样式
				console.log($("img").first().addClass("cc"));
               })

last() 获取匹配的最后一个元素

        <style>			
			.aa {
				box-shadow: 0px 0px 50px orchid;
			}
		</style>
		<script>
			$(function() {
				//last() 获取匹配的最后一个元素
				console.log($("img").last());
				//添加样式
				console.log($("img").last().addClass("aa"));
                })

eq(N)  根据下标获取匹配的元素  

               //eq(N)  根据下标获取匹配的元素    
				console.log($("img").eq(2));

filter(selector) 筛选出与指定表达式匹配的元素集合

          <style>
			.bb {
				border: 10px solid blue;
			}

			.aa {
				box-shadow: 0px 0px 50px orchid;
			}
		</style>
		<script>
			$(function() {
				//filter(selector) 筛选出与指定表达式匹配的元素集合
				console.log($("img").filter(".bb"));
				//添加样式
				console.log($("img").filter(".bb").addClass("aa"));
                 })

has(selector) 筛选出包含特定特点的元素的集合

          <style>
			.aa {
				box-shadow: 0px 0px 50px orchid;
			}
		</style>
		<script>
			$(function() {
				//has(selector) 筛选出包含特定特点的元素的集合
				console.log($("div").has("img"));
				//添加样式
				//选中div (里面有img,img要有class属性为aa)
				console.log($("div").has("img").addClass("aa"));
  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值