gpt4 book ai didi

jquery - 如何从每个语句退出(中断函数)?

转载 作者:行者123 更新时间:2023-12-03 21:52:52 24 4
gpt4 key购买 nike

例如我使用以下代码:

$("img").each(function(i){
x += $("img:eq(" + i ")").width();
if(some conditional) return;
});

返回后我不想向 x 添加任何内容,我该如何实现?

最佳答案

来自JQuery doco ...

We can break the $.each() loop at a particular iteration by making the callback function return false. Returning non-false is the same as a continue statement in a for loop; it will skip immediately to the next iteration.

所以本质上这意味着......

返回 false; = break;

返回 true;return; = 继续;

关于jquery - 如何从每个语句退出(中断函数)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5515109/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com