作者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://www.ptt.cc/bbs/Web_Design/M.1495902862.A.1B8.html
→ Kenqr: return false時會中止,value是'three'的時候才會是false 05/28 00:48
推 pm2001: 關鍵字 jquery each continue break 05/28 01:06
推 LPH66: 重點是一樓的「return false 時會中止」 05/28 06:20
→ LPH66: 換句話說「return 條件是繼續的條件」, 跟 while 一樣 05/28 06:20
→ LPH66: 也就是說概念上這等於是一個 do-while 迴圈 05/28 06:20
→ steven11329: Will stop running after "three" 05/28 22:07
→ steven11329: 翻中文是three之後才停止 05/28 22:07
→ steven11329: 他沒有寫錯,是你英文理解錯誤。 05/28 22:07