JQuery 过滤选择器
2017-12-17 21:01
225 查看
过滤选择器:第一次选择之后,再一次进行选择。
$('div') //选择器,第一次选择
$('div:first') //第一个元素
$('div:last') //最后一个元素
$('div:gt(2)') //下标大于2的所有元素。下标从0开始。
$('div:lt(2)') //下标小于2的所有元素。下标从0开始。前两个元素。
$('div:eq(2)') //下标等于2的元素。
$('div:not(#d1)') //不包含 #d1 的所有元素。
$('div:even') //下标为偶数的所有元素,下标从0开始。(第奇数个)
$('div:odd') //下标为奇数的所有元素,下标从0开始。(第偶数个)
$('div') //选择器,第一次选择
$('div:first') //第一个元素
$('div:last') //最后一个元素
$('div:gt(2)') //下标大于2的所有元素。下标从0开始。
$('div:lt(2)') //下标小于2的所有元素。下标从0开始。前两个元素。
$('div:eq(2)') //下标等于2的元素。
$('div:not(#d1)') //不包含 #d1 的所有元素。
$('div:even') //下标为偶数的所有元素,下标从0开始。(第奇数个)
$('div:odd') //下标为奇数的所有元素,下标从0开始。(第偶数个)
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> <style> td { color: white; } </style> <script src="scripts/jquery-1.7.1.min.js"></script> <script> var list = [ { id: '1', country: '中国', capital: '北京' }, { id: '2', country: '美国', capital: '华盛顿' }, { id: '3', country: '日本', capital: '东京' }, { id: '4', country: '韩国', capital: '首尔' } ]; $(function () { //遍历集合,创建tr与td $.each(list, function(index, item) { $('<tr><td>' + item.id + '</td><td>' + item.country + '</td><td>' + item.capital + '</td></tr>').appendTo('#list'); }); //为奇偶行指定不同背景色 $('#list tr:even').css('background-color', 'red'); $('#list tr:odd').css('background-color', 'green'); //指定鼠标移上、移开效果 $('#list tr').hover(function() {//鼠标移上 bgColor = $(this).css('background-color'); $(this).css('background-color', 'blue'); }, function() {//鼠标移开 $(this).css('background-color', bgColor); }); //前三名变粗 $('#list tr:lt(3)').css('font-weight', 'bold'); }); </script> </head> <body> <table border="1"> <thead> <th width="100">编号</th> <th width="100">国家</th> <th width="100">首都</th> </thead> <tbody id="list"> </tbody> </table> </body> </html>
相关文章推荐
- 【JQuery】:first和:last过滤选择器
- jquery选择器之基本过滤选择器
- a毛 jquery 学习记 4过滤选择器1
- 前端学习笔记-jquery-11-(过滤选择器)过滤器:可见性过滤器
- JQuery -- 介绍,选择器及其示例, 基本选择器,层次选择器,过滤选择器,表单选择器
- jQuery选择器 过滤选择器(五.子元素过滤选择器)
- Jquery过滤选择器
- jquery选择器之基本过滤选择器详解
- jquery属性过滤选择器
- jquery属性过滤选择器
- jQuery基础教程之强大的选择器(过滤选择器-表单对象属性过滤选择器)
- jQuery选择器介绍:基本选择器、层次选择器、过滤选择器、表单选择器
- jquery可见性过滤选择器使用示例
- jQuery基础教程之强大的选择器(过滤选择器-内容过滤选择器)
- JavaScript学习笔记8-jQuery内容过滤选择器、可见性过滤选择器深度解析
- jQuery选择器——基本过滤选择器
- Jquery实战学习--内容过滤选择器
- Jquery的过滤选择器
- jQuery选择器之基本过滤选择器Demo
- jQuery选择器的过滤器,即对选择的结果再进行一个过滤(如我不想要在<div id="test"></div>这里的input控件)