首页 >> js开发 >> jsjQuery--遍历操作实例小结【后代、同胞及过滤】js大全
jsjQuery--遍历操作实例小结【后代、同胞及过滤】js大全
children()
find()
children()find()children() 方法返回每个
$(document).ready(function(){
$("div").children();
});
$(document).ready(function(){
$("div").children();
});
返回类名为 "1" 的所有
元素,并且它们是
$(document).ready(function(){
$("div").children("p.1");
});
$(document).ready(function(){
$("div").children("p.1");
});
find() 方法返回属于
$(document).ready(function(){
$("div").find("span");
});
$(document).ready(function(){
$("div").find("span");
});
返回
$(document).ready(function(){
$("div").find("*");
});
$(document).ready(function(){
$("div").find("*");
});
jquery--遍历【同胞】在 DOM 树进行水平遍历:
siblings()
next()
nextAll()
nextUntil()
prev()
prevAll()
prevUntil()
siblings()next()nextAll()nextUntil()prev()prevAll()prevUntil()siblings() 方法返回
的所有同胞元素:
$(document).ready(function(){
$("h2").siblings();
});
$(document).ready(function(){
$("h2").siblings();
});
返回属于 的同胞元素的所有
元素:
$(document).ready(function(){
$("h2").siblings("p");
});
$(document).ready(function(){
$("h2").siblings("p");
});
next() 方法返回
的下一个同胞元素:
$(document).ready(function(){
$("h2").next();
});
$(document).ready(function(){
$("h2").next();
});
nextAll() 方法返回 的所有跟随的同胞元素:
$(document).ready(function(){
$("h2").nextAll();
});
$(document).ready(function(){
$("h2").nextAll();
});
nextUntil() 方法返回介于 与 元素之间的所有同胞元素:
$(document).ready(function(){
$("h2").nextUntil("h6");
});
$(document).ready(function(){
$("h2").nextUntil("h6");
});
prev(), prevAll() & prevUntil() 方法prev(), prevAll() 以及 prevUntil() 方法的工作方式与上面的方法类似,只不过方向相反而已:它们返回的是前面的同胞元素(在 DOM 树中沿着同胞之前元素遍历,而不是之后元素遍历)jQuery--遍历【过滤】缩小搜索元素的范围三个最基本的过滤方法是:first(), last() 和 eq(),它们允许您基于其在一组元素中的位置来选择一个特定的元素。其他过滤方法,比如 filter() 和 not() 允许您选取匹配或不匹配某项指定标准的元素。first() 方法选取首个 元素内部的第一个 元素:
$(document).ready(function(){
$("div p").first();
});
$(document).ready(function(){
$("div p").first();
});
last() 方法选择最后一个
元素中的最后一个 元素:
$(document).ready(function(){
$("div p").last();
});
$(document).ready(function(){
$("div p").last();
});
eq() 方法索引号从 0 开始,因此首个元素的索引号是 0 而不是 1。下面的例子选取第二个
元素(索引号 1):
$(document).ready(function(){
$("p").eq(1);
});
$(document).ready(function(){
$("p").eq(1);
});
filter() 方法返回带有类名 "url" 的所有
元素:
$(document).ready(function(){
$("p").filter(".url");
});
$("p.url").css("background-color","yellow"); //效果相同
$(document).ready(function(){
$("p").filter(".url");
});
$("p.url").css("background-color","yellow"); //效果相同
not() 方法not() 方法返回不匹配标准的所有元素。提示:not() 方法与 filter() 相反。下面的例子返回不带有类名 "url" 的所有
元素:
$(document).ready(function(){
$("p").not(".url");
});
$(document).ready(function(){
$("p").not(".url");
});
感兴趣的朋友可以使用在线HTML/CSS/JavaScript代码运行工具http://tools./code/HtmlJsRun测试上述代码运行效果。在线HTML/CSS/JavaScript代码运行工具在线HTML/CSS/JavaScript代码运行工具http://tools./code/HtmlJsRun关于jQuery相关内容还可查看本站专题:《jQuery遍历算法与技巧总结》、《jQuery操作DOM节点方法总结》、《jQuery扩展技巧总结》、《jquery选择器用法总结》及《jQuery常用插件及用法总结》jQuery遍历算法与技巧总结jQuery操作DOM节点方法总结jQuery扩展技巧总结jquery选择器用法总结jQuery常用插件及用法总结希望本文所述对大家jQuery程序设计有所帮助。
相关文章:
- js解决VUE mounted 钩子函数执行时 img 未加载导致页面布局的问题js大全
- js代码详解JavaScript自定义函数
- jsElement Breadcrumb 面包屑的使用方法js大全
- jsVue中的this.$options.data()和this.$data用法说明js大全
- js在vue中使用防抖函数组件操作js大全
- js解决vue的router组件component在import时不能使用变量问题js大全
- jsAngular利用HTTP POST下载流文件的步骤记录js大全
- js解决vue页面渲染但dom没渲染的操作js大全
- js解决vuex数据页面刷新后初始化操作js大全
- jsVue组件跨层级获取组件操作js大全
$(document).ready(function(){
$("h2").nextAll();
});
$(document).ready(function(){
$("h2").nextAll();
});
nextUntil() 方法返回介于
与 元素之间的所有同胞元素:
$(document).ready(function(){
$("h2").nextUntil("h6");
});
$(document).ready(function(){
$("h2").nextUntil("h6");
});
prev(), prevAll() & prevUntil() 方法prev(), prevAll() 以及 prevUntil() 方法的工作方式与上面的方法类似,只不过方向相反而已:它们返回的是前面的同胞元素(在 DOM 树中沿着同胞之前元素遍历,而不是之后元素遍历)jQuery--遍历【过滤】缩小搜索元素的范围三个最基本的过滤方法是:first(), last() 和 eq(),它们允许您基于其在一组元素中的位置来选择一个特定的元素。其他过滤方法,比如 filter() 和 not() 允许您选取匹配或不匹配某项指定标准的元素。first() 方法选取首个 元素内部的第一个 元素:
$(document).ready(function(){
$("div p").first();
});
$(document).ready(function(){
$("div p").first();
});
last() 方法选择最后一个
元素中的最后一个 元素:
$(document).ready(function(){
$("div p").last();
});
$(document).ready(function(){
$("div p").last();
});
eq() 方法索引号从 0 开始,因此首个元素的索引号是 0 而不是 1。下面的例子选取第二个
元素(索引号 1):
$(document).ready(function(){
$("p").eq(1);
});
$(document).ready(function(){
$("p").eq(1);
});
filter() 方法返回带有类名 "url" 的所有
元素:
$(document).ready(function(){
$("p").filter(".url");
});
$("p.url").css("background-color","yellow"); //效果相同
$(document).ready(function(){
$("p").filter(".url");
});
$("p.url").css("background-color","yellow"); //效果相同
not() 方法not() 方法返回不匹配标准的所有元素。提示:not() 方法与 filter() 相反。下面的例子返回不带有类名 "url" 的所有
元素:
$(document).ready(function(){
$("p").not(".url");
});
$(document).ready(function(){
$("p").not(".url");
});
感兴趣的朋友可以使用在线HTML/CSS/JavaScript代码运行工具http://tools./code/HtmlJsRun测试上述代码运行效果。在线HTML/CSS/JavaScript代码运行工具在线HTML/CSS/JavaScript代码运行工具http://tools./code/HtmlJsRun关于jQuery相关内容还可查看本站专题:《jQuery遍历算法与技巧总结》、《jQuery操作DOM节点方法总结》、《jQuery扩展技巧总结》、《jquery选择器用法总结》及《jQuery常用插件及用法总结》jQuery遍历算法与技巧总结jQuery操作DOM节点方法总结jQuery扩展技巧总结jquery选择器用法总结jQuery常用插件及用法总结希望本文所述对大家jQuery程序设计有所帮助。
相关文章:
- js解决VUE mounted 钩子函数执行时 img 未加载导致页面布局的问题js大全
- js代码详解JavaScript自定义函数
- jsElement Breadcrumb 面包屑的使用方法js大全
- jsVue中的this.$options.data()和this.$data用法说明js大全
- js在vue中使用防抖函数组件操作js大全
- js解决vue的router组件component在import时不能使用变量问题js大全
- jsAngular利用HTTP POST下载流文件的步骤记录js大全
- js解决vue页面渲染但dom没渲染的操作js大全
- js解决vuex数据页面刷新后初始化操作js大全
- jsVue组件跨层级获取组件操作js大全
$(document).ready(function(){
$("h2").nextUntil("h6");
});
$(document).ready(function(){
$("h2").nextUntil("h6");
});
prev(), prevAll() & prevUntil() 方法prev(), prevAll() 以及 prevUntil() 方法的工作方式与上面的方法类似,只不过方向相反而已:它们返回的是前面的同胞元素(在 DOM 树中沿着同胞之前元素遍历,而不是之后元素遍历)jQuery--遍历【过滤】缩小搜索元素的范围三个最基本的过滤方法是:first(), last() 和 eq(),它们允许您基于其在一组元素中的位置来选择一个特定的元素。其他过滤方法,比如 filter() 和 not() 允许您选取匹配或不匹配某项指定标准的元素。first() 方法选取首个
元素:
$(document).ready(function(){
$("div p").first();
});
$(document).ready(function(){
$("div p").first();
});
last() 方法选择最后一个
元素:
$(document).ready(function(){
$("div p").last();
});
$(document).ready(function(){
$("div p").last();
});
eq() 方法索引号从 0 开始,因此首个元素的索引号是 0 而不是 1。下面的例子选取第二个
元素(索引号 1):
$(document).ready(function(){
$("p").eq(1);
});
$(document).ready(function(){
$("p").eq(1);
});
filter() 方法返回带有类名 "url" 的所有
元素:
$(document).ready(function(){
$("p").filter(".url");
});
$("p.url").css("background-color","yellow"); //效果相同
$(document).ready(function(){
$("p").filter(".url");
});
$("p.url").css("background-color","yellow"); //效果相同
not() 方法not() 方法返回不匹配标准的所有元素。提示:not() 方法与 filter() 相反。下面的例子返回不带有类名 "url" 的所有
元素:
$(document).ready(function(){
$("p").not(".url");
});
$(document).ready(function(){
$("p").not(".url");
});
感兴趣的朋友可以使用在线HTML/CSS/JavaScript代码运行工具http://tools./code/HtmlJsRun测试上述代码运行效果。在线HTML/CSS/JavaScript代码运行工具在线HTML/CSS/JavaScript代码运行工具http://tools./code/HtmlJsRun关于jQuery相关内容还可查看本站专题:《jQuery遍历算法与技巧总结》、《jQuery操作DOM节点方法总结》、《jQuery扩展技巧总结》、《jquery选择器用法总结》及《jQuery常用插件及用法总结》jQuery遍历算法与技巧总结jQuery操作DOM节点方法总结jQuery扩展技巧总结jquery选择器用法总结jQuery常用插件及用法总结希望本文所述对大家jQuery程序设计有所帮助。
相关文章:
- js解决VUE mounted 钩子函数执行时 img 未加载导致页面布局的问题js大全
- js代码详解JavaScript自定义函数
- jsElement Breadcrumb 面包屑的使用方法js大全
- jsVue中的this.$options.data()和this.$data用法说明js大全
- js在vue中使用防抖函数组件操作js大全
- js解决vue的router组件component在import时不能使用变量问题js大全
- jsAngular利用HTTP POST下载流文件的步骤记录js大全
- js解决vue页面渲染但dom没渲染的操作js大全
- js解决vuex数据页面刷新后初始化操作js大全
- jsVue组件跨层级获取组件操作js大全