作者Telete (澡兰香)
看板Web_Design
标题[问题] jquery each
时间Sun May 28 00:34:19 2017
// 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啊
不是应该一开始就中止吗??
还请各位高人们解惑~~谢谢
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 220.136.38.172
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Web_Design/M.1495902862.A.1B8.html
1F:→ Kenqr: return false时会中止,value是'three'的时候才会是false 05/28 00:48
2F:推 pm2001: 关键字 jquery each continue break 05/28 01:06
3F:推 LPH66: 重点是一楼的「return false 时会中止」 05/28 06:20
4F:→ LPH66: 换句话说「return 条件是继续的条件」, 跟 while 一样 05/28 06:20
5F:→ LPH66: 也就是说概念上这等於是一个 do-while 回圈 05/28 06:20
6F:→ steven11329: Will stop running after "three" 05/28 22:07
7F:→ steven11329: 翻中文是three之後才停止 05/28 22:07
8F:→ steven11329: 他没有写错,是你英文理解错误。 05/28 22:07