gpt4 book ai didi

Javascript/JQuery : return immediately from PARENT function in call to each() via anon function

转载 作者:行者123 更新时间:2023-11-30 06:58:08 24 4
gpt4 key购买 nike

例如:

> function foo() {
> jQuery(whatever).each( function() {
return; // this just exits the anonymous function - is there a way to return from foo?
}
);
>
> }

最佳答案

**更正:添加了更多细节。使用标志允许从 PARENT 函数返回 **

function foo() {
var doreturn = false;
jQuery(whatever).each( function() {
if(youwanttoreturn){
doreturn=1;
return false;
}
});
if(doreturn)return;
}

http://api.jquery.com/each/“我们可以通过返回 false 从回调函数中停止循环。”

关于Javascript/JQuery : return immediately from PARENT function in call to each() via anon function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2601920/

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