jquery的$(selector).each(function(index,element))和$.each(dataresource,function(index,element))的区别
$(selector).each(function(index,element))
定义和用法
each() 方法规定为每个匹配元素规定运行的函数。
$(selector).each(function(index,element))
| 参数 | 描述 |
|---|---|
| function(index,element) |
必需。为每个匹配元素规定运行的函数。
|
作用:在dom方面用的较多
示例:
html部分文档
<ul id="each_id">
<li>Coffee</li>
<li>Soda</li>
<li>Milk</li>
</ul>
js遍历函数:
$("li").each(function(){
alert($(this).text())
});
效果



$.each(dataresource,function(index,element))
作用:在数据处理上用的比较多
示例:
此处没有html代码,只有js代码,如下:
function traversalData(){
var jsonResourceList = '[{"id":"1","tagName":"apple"},{"id":"2","tagName":"orange"},{"id":"3","tagName":"banana"},{"id":"4","tagName":"watermelon"}]';
if(jsonResourceList.length >0){
$.each(JSON.parse(jsonResourceList), function(index, obj) {
alert(obj.tagName);
});
}
}
输出结果:
最终结论:
在遍历DOM时,通常用$(selector).each(function(index,element))函数;
在遍历数据时,通常用$.each(dataresource,function(index,element))函数。
参考自:http://www.w3school.com.cn/jquery/traversing_each.asp
https://blog.csdn.net/gao_xu_520/article/details/78588977
jquery的$(selector).each(function(index,element))和$.each(dataresource,function(index,element))的区别的更多相关文章
- jQuery Custom Selector JQuery自定义选择器
什么是JQuery的选择器呢,详见JQuery中的Selector: http://docs.jquery.com/Selectors 比如 $("div:contains('John')& ...
- jquery 选择器(selector)和事件(events)
页面加载完成后开始运行do stuff when DOM is ready 中的语句! $(document).ready(function() { // do stuff when DO ...
- jQuery.Deferred exception: $.get is not a function TypeError: $.get is not a function
/********************************************************************** * jQuery.Deferred exception: ...
- DOM方法index()相关问题(为何$(this).index(this)是错误的 )
写jQuery的时候遇到一个关于index()的问题,查找相关资料后,解决了,把自己的想法写在下面. index() 方法返回指定元素相对于其他指定元素的 index 位置. 完全语法为:$(sele ...
- 2、jQuery的基本概念-必看-版本-入口函数- jq对象和dom对象区别
1.4. jQuery的版本 官网下载地址:http://jquery.com/download/ jQuery版本有很多,分为1.x 2.x 3.x 大版本分类: 1.x版本:能够兼容IE678浏览 ...
- ORA-01502: index 'INDEX_NAME' or partition of such index is in unusable state
ORA-01502: index 'INDEX_NAME' or partition of such index is in unusable state 原因: 这个错误一般是因为索引状态为UNUS ...
- ORA-01502: index ‘index_name' or partition of such index is in unusable state
错误现象: 今天发布脚本时,一个表插入数据时报如下错误 ORA-01502: index ‘index_name' or partition of such index is in unusable ...
- Function接口 – Java8中java.util.function包下的函数式接口
Introduction to Functional Interfaces – A concept recreated in Java 8 Any java developer around the ...
- JS function的定义方法,及function对象的理解。
废话篇: 今天看到了Function的内容,各种晕,各种混淆有木有.简直是挑战个人脑经急转弯的极限啊.不过,最终这一难题还是被我攻克了,哇咔咔.现在就把这东西记下来,免得到时候又忘了就悲催了.... ...
随机推荐
- php_screw安装,使用
安装步骤:1. 下载源码:wget http://nchc.dl.sourceforge.net/project/php-screw/php-screw/1.5/php_screw-1.5.tar.g ...
- ORACLE 数据库使用正则表达式重新计算指定位置的数字为新的数字
昨天工作中遇到这个问题: 有一个这样的字符串expression变量,里面可能存储的值类似于以下[Index_CivilWork,0]*(1+[Y10814,1])/[Y10674,1] [300,1 ...
- listener.starting()源码探究
容器启动时,监听器调用starting方法,本质是找到匹配的监听器,广播事件,开始监听 上节对寻找匹配监听器做了分析,其是这个过程比较重要的部分,本文开始监听,反而不是那么复杂,如下: 找匹配监听器就 ...
- Some elementary algorithms on discrete differential geometry(DDGSpring2016 Demos)
I studied the on-line course(http://brickisland.net/DDGSpring2016/) by myself, and here are the scre ...
- [蓝桥杯]PREV-19.历届试题_九宫重排
题目描述: 代码如下: #include <stdio.h> #include <stdlib.h> #include <string.h> #define N 1 ...
- UEFI引导过程及windows引导修复
UEFI启动是一种新的主板引导项.传统引导方式就是Legacy模式. CSM的选项是UEFI模拟Legacy模式启动,选中后则可使用Legacy模式启动机器. Legacy模式仅支持传统的MBR分区, ...
- Mysql在sql中截取时间类型字段的年月日
//显示年月日 select date_format(date ,'%Y-%m-%d' ) from talbe_a //根据年月日分组 select date_format(date ,'%Y-%m ...
- 继承LinearLayout自定义左侧菜单
public class LeftMenuView extends LinearLayout { LinkedHashMap<Integer,String> map=new LinkedH ...
- [UE4]模拟物理
一.默认情况下Actor的Mobility(可移动性)是Static(静止),Simulate Physics(模拟物理):如果勾选Simulate Physics,则Mobility会自动变成Mov ...
- 刘志梅201771010115.《面向对象程序设计(java)》第十六周学习总结
实验十六 线程技术 实验时间 2017-12-8 1.实验目的与要求 (1)当线程的run方法执行方法体中最后一条语句后,并经由执行return语句返回时,或者出现了在方法中没有捕获的异常时,线程将 ...