[问题] jQuery each

楼主: Telete (艾小可)   2017-05-28 00:34:19
// ARRAYS
var arr = [
'one',
'two',
'three',
'four',
'five'
];
$.each(arr, function (index, value) {
console.log(value);
// Will stop running after "three"
return (value !== 'three');
});
// Outputs: one two three
因为不懂jQuery 的 each方法所以去找了教学
看网络上的范例是这样写的
想请教的是,最后面的outputs
为何是 one two three
return (value !== 'three');
这是表示,假如值不是three的话就中止吧
那 one two 也不是 three啊
不是应该一开始就中止吗??
还请各位高人们解惑~~谢谢
作者: Kenqr (function(){})()   2017-05-28 00:48:00
return false时会中止,value是'three'的时候才会是false
作者: pm2001 (做个盾牌眼球兵吧)   2017-05-28 01:06:00
关键字 jquery each continue break
作者: LPH66 (-6.2598534e+18f)   2017-05-28 06:20:00
重点是一楼的“return false 时会中止”换句话说“return 条件是继续的条件”, 跟 while 一样也就是说概念上这等于是一个 do-while 循环
作者: steven11329 (清新柳橙)   2017-05-28 22:07:00
Will stop running after "three"翻中文是three之后才停止他没有写错,是你英文理解错误。

Links booklink

Contact Us: admin [ a t ] ucptt.com