[問題] jQuery each

看板Web_Design作者 (澡蘭香)時間8年前 (2017/05/28 00:34), 編輯推噓2(206)
留言8則, 4人參與, 最新討論串1/1
// 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

05/28 00:48, , 1F
return false時會中止,value是'three'的時候才會是false
05/28 00:48, 1F

05/28 01:06, , 2F
關鍵字 jquery each continue break
05/28 01:06, 2F

05/28 06:20, , 3F
重點是一樓的「return false 時會中止」
05/28 06:20, 3F

05/28 06:20, , 4F
換句話說「return 條件是繼續的條件」, 跟 while 一樣
05/28 06:20, 4F

05/28 06:20, , 5F
也就是說概念上這等於是一個 do-while 迴圈
05/28 06:20, 5F

05/28 22:07, , 6F
Will stop running after "three"
05/28 22:07, 6F

05/28 22:07, , 7F
翻中文是three之後才停止
05/28 22:07, 7F

05/28 22:07, , 8F
他沒有寫錯,是你英文理解錯誤。
05/28 22:07, 8F
文章代碼(AID): #1PAQgE6u (Web_Design)
文章代碼(AID): #1PAQgE6u (Web_Design)