/*
* 数组的forEach方法:
* 1、返回给回调的参数先是值,然后是下标
* 2、回调函数执行时内部的this指向window
* */
/*var arr = [1,2,3,4,5];
arr.forEach(function( val, index ) {
console.log( val, index, this );
});*/

/*
* jQ实例的each方法,
* 1、返回给回调的参数先是下标,然后是值
* 2、回调函数执行时内部的this就指向遍历到的每一个值(就是回调中接收到的val)
* 3、如果想中断遍历,在回调中返回false即可
* */
/*$('li').each( function( index, val ) {

console.log( index, val, this );

if( index === 1 ) {
return false;
}
});*/

/*
* jQ还提供了一个静态版本的each方法,供框架使用者使用
* 1、返回给回调的参数先是下标,然后是值
* 2、回调函数执行时内部的this就指向遍历到的每一个值(就是回调中接收到的val)
* 3、如果想中断遍历,在回调中返回false即可
* */
var obj = { name: 'test', val: {} };
var arr2 = [ 'abc', {}, 'qwer' ];

$.each( obj, function( key, val ) {
console.log( key, val, this );
} );

$.each( arr2, function( index, val ) {
console.log( index, val, this );
} );

数组的foreach方法和jQuery中的each方法的更多相关文章

  1. jQuery.extend()方法和jQuery.fn.extend()方法

    jQuery.extend()方法和jQuery.fn.extend()方法源码分析 这两个方法用的是相同的代码,一个用于给jQuery对象或者普通对象合并属性和方法一个是针对jQuery对象的实例, ...

  2. jquery中的ajax方法参数的用法和他的含义

    jquery中的ajax方法参数的用法和他的含义: 1.url:  要求为String类型的参数,(默认为当前页地址)发送请求的地址. 2.type:  要求为String类型的参数,请求方式(pos ...

  3. json库的编译方法和vs2010中导入第三方库的方法

    json库的编译方法和vs2010中导入第三方库的方法 一.去相应官网下载json.cpp文件 Jsoncpp下载:https://sourceforge.net/projects/jsoncpp/  ...

  4. jquery 中一些 特殊方法 的特殊使用 一览表

    cnblogs的页面, 一种是管理页面, 是随笔的列表 a full list of essays. 另一种是 首页. 要搜索文档的话, 就使用 "首页"的那种方式. 一个jque ...

  5. 解决关于jquery中$.get()方法总是报“HierarchyRequestError: Node cannot be inserted at the specified point in the hierarchy”错的方法

    解决关于jquery中$.get()方法总是报“HierarchyRequestError: Node cannot be inserted at the specified point in the ...

  6. jQuery中的join方法

    和JS 中的JOIN 方法一样,将一数组按照JOIN的参数连接起来.比如: var arr = [ "a", "b", "c", " ...

  7. 用JQuery中的Ajax方法获取web service等后台程序中的方法

    用JQuery中的Ajax方法获取web service等后台程序中的方法 1.准备需要被前台html页面调用的web Service,这里我们就用ws来代替了,代码如下: using System; ...

  8. $.ajax()方法详解 jquery中的ajax方法

    jquery中的ajax方法参数总是记不住,这里记录一下. 1.url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. 2.type: 要求为String类型的参数,请求方式(p ...

  9. jquery中的ajax方法参数

    引用来自:http://www.cnblogs.com/tylerdonet/p/3520862.html jquery中的ajax方法参数总是记不住,这里记录一下. 1.url: 要求为String ...

随机推荐

  1. VB6 GDI+ 入门教程[4] 文字绘制

    http://vistaswx.com/blog/article/category/tutorial/page/2 VB6 GDI+ 入门教程[4] 文字绘制 2009 年 6 月 18 日 7条评论 ...

  2. RemoteWebDriver管理

    直接贴代码: @Parameters({"BrowserType","NodeIP","NodePort"}) public void be ...

  3. 关于json的理解

    一. 获取数组长度 array.length 获取对象长度  Object.keys(objs).length 二. 如何抉择{}和[] 先说两者区别, {}:父类下面直接是子类名称 []:父类下会追 ...

  4. 向html中添加节点

    简单: ①,js中: (function () { var box=document.querySelector("#box"); var con1=document.create ...

  5. [saiku] 配置spring-security 允许 iframe加载saiku首页

    最近提出了一个需求:在一个iframe中展现saiku首页 呵呵,这还不简单. 直接<iframe src="http://localhost:8080/saiku" /&g ...

  6. LDM和STM指令

    LDM批量加载/STM批量存储指令可以实现一组寄存器和一块连续的内存单元之间传输数据. 允许一条指令传送16个寄存器的任意子集和所有寄存器,指令格式如下: LDM{cond}  mode  Rn{!} ...

  7. Redis(7)Creating and Using Cluster Mode

    1. DocumentsCluster will not support SELECT, it only contains database 0.All the nodes use TCP bus a ...

  8. 《转》---使用递归方法DataTable 绑定 TreeView

    转自:http://blog.sina.com.cn/s/blog_8944756d01016yaj.html 前台: <asp:View ID="view0" runat= ...

  9. Java集合——List接口

    1.定义 List是Collection的子接口,元素有序并且可以重复,表示线性表. 2.方法 add(int index,Object e):在指定索引(和数组下标类似,为0,1,2....)放入元 ...

  10. li排序的两种方法

    1.一般做法 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <ti ...