$().each 在dom处理上面用的较多。如果页面有多个input标签类型为checkbox,对于这时用$().each来处理多个checkbook,例如:

$(“input[name=’ch’]”).each(function(i){
if($(this).attr(‘checked’)==true)
{
//一些操作代码
}
回调函数是可以传递参数,i就为遍历的索引。 遍历一个数组通常用$.each()来处理  例如:

$.each([{name:"limeng",email:"xfjylimeng"},{name:"hehe",email:"xfjylimeng"}],function(i,n)
{
alert("索引:"+i+"对应值为:"+n.name);
});

参数i为遍历索引值,n为当前的遍历对象.

var arr2 = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
$.each(arr2, function(i, item){
alert(item[0]);
});
输出:1   4   7

随机推荐

  1. LeetCode OJ:Linked List Cycle II(循环链表II)

    Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Note ...

  2. LeetCode OJ:Next Permutation(下一排列)

    Implement next permutation, which rearranges numbers into the lexicographically next greater permuta ...

  3. Creating a Game with CocosBuilder

    Creating a Game with CocosBuilder This tutorial aims to show how you can use CocosBuilder together w ...

  4. I.MX6 Android 设备节点权限

    /********************************************************************************** * I.MX6 Android ...

  5. (六)js常见四大排序

    今天突然想回顾一下四大排序,虽然说在实战中没有用到,但是想回顾一下四大排序的思想   var arr = [23, 34, 11, 22, 19, 18];   1.冒泡排序: 冒泡排序的思路分析: ...

  6. PHPCMS V9调用父栏目 顶级父栏目的代码

    一.调用父栏目 首先是列表页和二级栏目页list.html {$CATEGORYS[$top_parentid][catname]} //顶级父栏目名称 {$CATEGORYS[$CAT[parent ...

  7. opencv之图像滤波

    均值滤波 均值滤波函数cv2.blur() import cv2 img = cv2.imread('01.jpg') blur = cv2.blur(img,(5,5)) cv2.imshow(&q ...

  8. 重温CLR(二)生成、部署以及程序集

    将类型生成到模块中 class Program { static void Main(string[] args) { Console.WriteLine("Hi"); } } 该 ...

  9. 【spring源码学习】springMVC之映射,拦截器解析,请求数据注入解析,DispatcherServlet执行过程

    [一]springMVC之url和bean映射原理和源码解析 映射基本过程 (1)springMVC配置映射,需要在xml配置文件中配置<mvc:annotation-driven >  ...

  10. LA3218 Find the Border

    题意 PDF 分析 虽然只找外轮廓,但是时间复杂度不比PSLG优秀,所以可以当做联系PSLG的题做. PSLG框架 找出所有交点 交点按序连边 把边按极角序排序 逆时针找圈 然后何以会顺时针找出无限区 ...