jQuery each()小议
作者:bea
代码如下: var arr1 = [ "one", "two", "three", "four", "five" ]; $.each(arr1, function(){ alert(this); }); 输出:one two three four five 代码如下: var arr2 = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] $.each(arr2, function(i, item){ 参数的名字可以自己定义,each
代码如下:
var arr1 = [ "one", "two", "three", "four", "five" ];
$.each(arr1, function(){
alert(this);
});
输出:one two three four five
代码如下:
var arr2 = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
$.each(arr2, function(i, item){ 参数的名字可以自己定义,each方法会根据第一个参数(arr2)的格式而判断回调函数方法体语法的正确性
alert(item[0]);
});
输出:1 4 7
代码如下:
var obj = { one:1, two:2, three:3, four:4, five:5 };
$.each(obj, function(key, val) {
alert(obj[key]);
});
输出:1 2 3 4 5
代码如下:
$.each($("input:hidden"), function(){
alert(this.name);
});
$.each($("input:hidden"), function(){
alert(this.value);
});
跳出遍历
代码如下:
$(document).ready(
function test()
{ var index=0;
var arr1 = [[1, 4, 3], [4, 6, 6], [7, 20, 9]]
$.each(arr1, function(i,item){
if(i==1)
{
alert("点击继续下次遍历");
return ; //return false ;则跳出遍历
}
alert('索引'+i+'_'+item[0]);
});
})
有用 | 无用
猜你喜欢
您可能感兴趣的文章:
- window.location.hash 属性使用说明
- 对 lightbox JS 图片控件进行了一下改造, 使其他支持复杂的图片说明
- js 强制弹出窗口代码研究-又一款代码
- js 数组克隆方法 小结
- vs2003 js文件编码问题的解决方法
- Jquery AutoComplete自动完成 的使用方法实例
- JavaScript 对象的属性和方法4种不同的类型
- jQuery 前的按键判断代码
- Javascript 匿名函数及其代码模式原理
- JS 有名函数表达式全面解析
- Jquery Ajax学习实例6 向WebService发出请求,返回DataSet(XML) 异步调用
- JavaScript 高效运行代码分析
- JS setCapture 区域外事件捕捉
- javascript 实现滚动效果代码整理
- JavaScript 无缝上下左右滚动加定高定宽停顿效果(兼容ie/ff)
- 小议Javascript中的this指针
- js实现的类marquee水平循环滚动
- js 把字符串当函数执行的方法
- jQuery each()方法的使用方法