jquery-5  jQuery筛选选择器

一、总结

一句话总结:选择器加动态添加方法可以不用想方法名,这个简单方便。

1、筛选选择器有哪三种?

过滤 查找 串联

1.过滤

eq();
first();
last();
not();
slice();

2.查找

children();
find();
next();
nextAll();
parent();
prev();
prevAll();
siblings();

3.串联

add();
andSelf();

2、筛选选择器中的查找有哪几种?

子代 后代 邻接 兄弟 父亲 之前

children();
find();
next();
nextAll();
parent();
prev();
prevAll();
siblings();

3、筛选选择器中的过滤选择器有哪五种?

索引 第一个  最后一个  非 片段

eq();
first();
last();
not();
slice();

4、筛选选择器串联有哪两种?

增加和增加自己

add();
andSelf();

5、选择器和筛选的区别是什么?

使用this的时候选择器不好用,筛选比较好用

28 $('.div1').click(function(){
29 //使用筛选来实现
30 $(this).children('h1').css({'color':'#00f'});
31 });

6、jquery可以链式操作么?

可以

33 $('button').click(function(){
34 $(this).parent().parent().next().children().children().children().css({'color':'#00f'});
35 });

7、多选框反选怎么实现?

非checked属性

77 $('#unall').click(function(){
78 $(':checkbox').each(function(){
79 this.checked=!this.checked;
80 });
81 });

8、多选框全选怎么实现?

attr,checked属性

69 $('#all').click(function(){
70 $(':checkbox').attr({'checked':true});
71 });

二、jQuery筛选选择器

1、相关知识

筛选:

1.过滤

eq();
first();
last();
not();
slice();

2.查找

children();
find();
next();
nextAll();
parent();
prev();
prevAll();
siblings();

3.串联

add();
andSelf();

2、代码

选择器和筛选的区别(这里用选择器不好实现)

 <!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>index</title>
<style>
*{
font-family: 微软雅黑;
}
.div1{
background: #ccc;
cursor: pointer;
}
</style>
<script src="jquery.js"></script>
</head>
<body>
<div class='div1'>
<h1>aaaaaaaaaaaaaaaaaaa</h1>
<h1>aaaaaaaaaaaaaaaaaaa</h1>
<div class="div2">
<h1>bbbbbbbbbbbbbbbbbbbbb</h1>
<h1>bbbbbbbbbbbbbbbbbbbbb</h1>
</div>
</div>
</body>
<script>
$('.div1').click(function(){
//使用筛选来实现
$(this).children('h1').css({'color':'#00f'});
});
</script>
</html>

siblings前后所有兄弟

 <!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>index</title>
<style>
*{
font-family: 微软雅黑;
}
</style>
<script src="jquery.js"></script>
</head>
<body>
<h1>cccccccccccccccccccccc</h1>
<h1>cccccccccccccccccccccc</h1>
<div class='div1'>
<h1>aaaaaaaaaaaaaaaaaaa</h1>
<h1>aaaaaaaaaaaaaaaaaaa</h1>
<div class="div2">
<h1>bbbbbbbbbbbbbbbbbbbbb</h1>
<h1>bbbbbbbbbbbbbbbbbbbbb</h1>
</div>
</div>
<h1>cccccccccccccccccccccc</h1>
<h1>cccccccccccccccccccccc</h1>
</body>
<script>
$('.div1').siblings().css({'color':'#00f'});
</script>
</html>

prevAll前面所有兄弟

 <!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>index</title>
<style>
*{
font-family: 微软雅黑;
}
</style>
<script src="jquery.js"></script>
</head>
<body>
<h1>cccccccccccccccccccccc</h1>
<h1>cccccccccccccccccccccc</h1>
<h1>cccccccccccccccccccccc</h1>
<h1>cccccccccccccccccccccc</h1>
<div class='div1'>
<h1>aaaaaaaaaaaaaaaaaaa</h1>
<h1>aaaaaaaaaaaaaaaaaaa</h1>
<div class="div2">
<h1>bbbbbbbbbbbbbbbbbbbbb</h1>
<h1>bbbbbbbbbbbbbbbbbbbbb</h1>
</div>
</div>
</body>
<script>
$('.div1').prevAll().css({'color':'#00f'});
</script>
</html>

nextAll后面所有兄弟

 <!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>index</title>
<style>
*{
font-family: 微软雅黑;
}
</style>
<script src="jquery.js"></script>
</head>
<body>
<div class='div1'>
<h1>aaaaaaaaaaaaaaaaaaa</h1>
<h1>aaaaaaaaaaaaaaaaaaa</h1>
<div class="div2">
<h1>bbbbbbbbbbbbbbbbbbbbb</h1>
<h1>bbbbbbbbbbbbbbbbbbbbb</h1>
</div>
</div>
<h1>cccccccccccccccccccccc</h1>
<h1>cccccccccccccccccccccc</h1>
<h1>cccccccccccccccccccccc</h1>
<h1>cccccccccccccccccccccc</h1>
</body>
<script>
// $('.div1').children('h1').css({'color':'#00f'});
$('.div1').nextAll().css({'color':'#00f'});
</script>
</html>

find后代查找

 <!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>index</title>
<style>
*{
font-family: 微软雅黑;
}
</style>
<script src="jquery.js"></script>
</head>
<body>
<div class='div1'>
<h1>aaaaaaaaaaaaaaaaaaa</h1>
<h1>aaaaaaaaaaaaaaaaaaa</h1>
<div class="div2">
<h1>bbbbbbbbbbbbbbbbbbbbb</h1>
<h1>bbbbbbbbbbbbbbbbbbbbb</h1>
</div>
</div>
</body>
<script>
// $('.div1').children('h1').css({'color':'#00f'});
$('.div1').find('h1').css({'color':'#00f'});
</script>
</html>

next关系查找

 <!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>index</title>
<style>
*{
font-family: 微软雅黑;
}
</style>
<script src="jquery.js"></script>
</head>
<body>
<div>
<div>
<button>打小金</button>
</div>
</div> <div>
<div>
<div>
<h1>aaaaaaaaaaaaaaaaaaaaaa</h1>
<p>aaaaaaaaaaaaaaaaaaaaaaaa</p>
<h1>bbbbbbbbbbbbbbbbbbbbbb</h1>
<p>bbbbbbbbbbbbbbbbbbbbbbbbbb</p>
</div>
</div>
</div> </body>
<script>
$('button').click(function(){
$(this).parent().parent().next().children().children().children().css({'color':'#00f'});
});
</script>
</html>

parent、prev、children关系查找

 <!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>index</title>
<style>
*{
font-family: 微软雅黑;
}
</style>
<script src="jquery.js"></script>
</head>
<body>
<div>
<div>
<div>
<h1>aaaaaaaaaaaaaaaaaaaaaa</h1>
<p>aaaaaaaaaaaaaaaaaaaaaaaa</p>
<h1>bbbbbbbbbbbbbbbbbbbbbb</h1>
<p>bbbbbbbbbbbbbbbbbbbbbbbbbb</p>
</div>
</div>
</div> <div>
<div>
<button>打小金</button>
</div>
</div>
</body>
<script>
$('button').click(function(){
$(this).parent().parent().prev().prev().children().children().children().css({'color':'#00f'});
});
</script>
</html>

andSelf串联上自己

 <!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>index</title>
<style>
*{
font-family: 微软雅黑;
}
</style>
<script src="jquery.js"></script>
</head>
<body>
<div>
<h1>aaaaaaaaaaaaaaaaa</h1>
<h1>aaaaaaaaaaaaaaaaa</h1>
</div>
<h1>bbbbbbbbbbbbbbbbbbb</h1>
</body>
<script>
$('div').next().andSelf().css({'color':'#00f'});
</script>
</html>

add组合串联筛选

 <!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>index</title>
<style>
*{
font-family: 微软雅黑;
}
</style>
<script src="jquery.js"></script>
</head>
<body>
<h1>00001</h1>
<h1>00002</h1>
<hr>
<p>00003</p>
<p>00004</p>
</body>
<script>
$('h1').add('p').css({'color':'#00f'});
</script>
</html>

过滤筛选

 <!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>index</title>
<style>
*{
font-family: 微软雅黑;
}
</style>
<script src="jquery.js"></script>
</head>
<body>
<h1>00001</h1>
<h1>00002</h1>
<h1>00003</h1>
<h1>00004</h1>
<h1>00005</h1>
</body>
<script>
// $('h1').eq(0).css({'color':'#00f'});
// $('h1').not($('h1').eq(0)).css({'color':'#00f'});
// $('h1').first().css({'color':'#00f'});
// $('h1').last().css({'color':'#00f'});
$('h1').slice(1).css({'color':'#00f'});
</script>
</html>

checked找到所有被选中的人

 <!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>index</title>
<style>
*{
font-family: 微软雅黑;
}
</style>
<script src="jquery.js"></script>
</head>
<body>
<form action="">
<p>选择爱好:</p>
<p>
<label>
<input type="checkbox" name="" id=""> 打篮球
</label>
</p>
<p>
<label>
<input type="checkbox" name="" id=""> 踢足球
</label>
</p>
<p>
<label>
<input type="checkbox" name="" id=""> 去游泳
</label>
</p>
<p>
<label>
<input type="checkbox" name="" id=""> 去游泳
</label>
</p>
<p>
<label>
<input type="checkbox" name="" id=""> 去游泳
</label>
</p>
<p>
<label>
<input type="checkbox" name="" id=""> 去游泳
</label>
</p>
<p>
<label>
<input type="checkbox" name="" id=""> 去游泳
</label>
</p>
<p>
<label>
<input type="checkbox" name="" id=""> 去游泳
</label>
</p>
</form>
<p>
<button id='all'>全选</button>
<button id='notall'>全不选</button>
<button id='unall'>反选</button>
<button id='ok'>ok</button>
</p>
<hr>
<div class='info'> </div>
</body>
<script>
$('#all').click(function(){
$(':checkbox').attr({'checked':true});
}); $('#notall').click(function(){
$(':checkbox').attr({'checked':false});
}); $('#unall').click(function(){
$(':checkbox').each(function(){
this.checked=!this.checked;
});
}); $('#ok').click(function(){
$(':checked').parent().parent().appendTo('.info');
});
</script>
</html>
 
 
 
 

jquery-5 jQuery筛选选择器的更多相关文章

  1. jquery 子元素筛选选择器

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-type" content ...

  2. jQuery的筛选选择器

    基本筛选选择器 很多时候我们不能直接通过基本选择器与层级选择器找到我们想要的元素,为此jQuery提供了一系列的筛选选择器用来更快捷的找到所需的DOM元素.筛选选择器很多都不是CSS的规范,而是jQu ...

  3. Jquery | 基础 | 慕课网 | 基本筛选选择器

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-type" content ...

  4. jQuery选择器之表单对象属性筛选选择器

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-type" content ...

  5. jQuery选择器之属性筛选选择器

    在这么多属性选择器中[attr="value"]和[attr*="value"]是最实用的 [attr="value"]能帮我们定位不同类型 ...

  6. jquery 表单对象属性筛选选择器

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-type" content ...

  7. jquery 属性筛选选择器

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-type" content ...

  8. jquery 内容筛选选择器

    基本筛选选择器针对的都是元素DOM节点,如果我们要通过内容来过滤,jQuery也提供了一组内容筛选选择器,当然其规则也会体现在它所包含的子元素或者文本内容上 注意事项: :contains与:has都 ...

  9. 7、前端--jQuery简介、基本选择器、基本筛选器、属性选择器、表单选择器、筛选器方法、节点操作、绑定事件

    jQuery简介 宗旨:Write less, do more. 内部封装了js代码 是编程更加简单并且兼容所有的主流浏览器 版本:1.x 2.x 3.x # 可以使用3.x最新版 是第三方的类库:使 ...

随机推荐

  1. Zabbix监控Tomcat,Redis

    一 Tomcat监控 1.1.1 Tomcat 端配置 JMX 编辑catalina.sh文件,配置如下: CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.m ...

  2. c#中文字符串与byte数组互相转化

    因为中文字符串一个字符占两个字节,所以不能用正常的方式与byte之间进行互相转化 中文字符串转成byte[] byte[] ping = Encoding.UTF8.GetBytes("你的 ...

  3. pycharm 配置autopep8(亲测可行)

    autopep8是一个可以将Python代码自动排版为PEP8风格第三方包,使用它可以轻松地排版出格式优美整齐的代码.网络上有很多介绍如何在pycharm中配置autopep8的方案,但很多方案中还是 ...

  4. 28. Spring Boot配置方式

    转自:https://blog.csdn.net/webzhuce/article/details/54564019

  5. 10.static_extern

    另一个文件声明 #include <iostream> using namespace std; ; void show() { cout << " << ...

  6. 移动开发js库Zepto.js使用中的一些注意点

    来自http://chaoskeh.com/blog/some-experience-of-using-zepto.html的参考. 前段时间完成了公司一个产品的 HTML5 触屏版,开发中使用了 Z ...

  7. DriverModule_01

    最小驱动模块: 最简单的Makefile 无配置文件 最小驱动的四部分 头文件 声明模块信息 模块驱动的入口.出口 功能区 关于这个头文件的分析: linux头文件的位置,例如#include< ...

  8. Spring MVC基础了解

    参考网址:https://www.yiibai.com/spring_mvc/springmvc_overview.html Spring框架相关 Spring Security 一个灵活强大的身份验 ...

  9. 【例题 7-5 UVA - 129】Krypton Factor

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 每次枚举增加一个字符; 然后看看新生成的字符的后缀里面有没有出现连续子串就好,前面已经确认过的没必要重复确认 (枚举长度为偶数的一个 ...

  10. 当数据库没有备份,redo或undo损坏

    数据库在没有备份的情况下,如果数据库redo或undo损坏,可以通过如下方法处理,但是不一定成功 把init文件中的: undo_management=manual 然后启动数据库到mount 状态后 ...