我在 JavaScript 中使用循环嵌套了 switch,如下所示:
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 )
}
if !脚本是假的,我询问用户是否要继续其他复选框,如果他取消,我想打破循环并执行函数中的剩余语句。看起来像是休息;在执行 switch 的确认对话框中,如何使其运行 for 循环。
任何建议将不胜感激。
这正是labels https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/label是给:
theloop:
for (var i = 0; i < checkBoxIds.length; i++) {
...
switch (id.substring(id.length - 3)) {
...
break theloop;
// continue theloop;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)