gpt4 book ai didi

for循环中断中的Javascript切换;冲突

转载 作者:行者123 更新时间:2023-12-04 15:53:18 30 4
gpt4 key购买 nike

我在 JavaScript 中嵌套了循环开关,例如:

for (var i = 0; i < checkBoxIds.length; i++) {
if ($('#' + checkBoxIds[i]).prop('checked')) {
var id = checkBoxIds[i];
var assetCat = id.substring(0, 4);
switch (id.substring(id.length - 3)) {
case "scr":
if (!sscripts)
if (confirm("Name of scripts sub-folder (in shared) is not provided for " + assetCat + ". Press OK to Continue for others?"))
continue; else break; //else return
//Appending chrs or sets or props to scripts
switchAssets(sscripts, IdEnum.SCRIPTS);
break;
case "shd":
if (!sshaders)
if (confirm("Name of shaders sub-folder (in shared) is not provided for " + assetCat + ". Press OK to Continue for others?"))
continue; else break; //else return
//Appending chrs or sets or props to shaders
switchAssets(sshaders, IdEnum.SHADERS);
break;
case "sim":
if (!ssourceimages)
if (confirm("Name of sourceimages sub-folder (in shared) is not provided for " + assetCat + ". Press OK to Continue for others?"))
continue; else break; //else return
//Appending chrs or sets or props to sourceimages
switchAssets(ssourceimages, IdEnum.SOURCEIMAGES);
break;
default:
}
}
}

//...Still doing something (else return; will never kiss this :D )
}

如果 !sscripts 是假的,我会询问用户是否要继续其他复选框,如果他取消,我想打破循环并在函数内执行剩余的语句。好像要休息了;在执行开关的确认对话框中,我怎样才能让它运行 for 循环。

如有任何建议,我们将不胜感激。

最佳答案

这正是labels用于:

theloop:
for (var i = 0; i < checkBoxIds.length; i++) {
...

switch (id.substring(id.length - 3)) {

...
break theloop;
// continue theloop;

关于for循环中断中的Javascript切换;冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18821031/

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