javascript - 需要带条件继续的循环
问题描述
我需要基于复选框“继续”。
HTML:
<input type = "text" id = "E1" /><input type="checkbox" id="C1">
<input type = "text" id = "E2" /><input type="checkbox" id="C2">
<input type = "text" id = "E3" /><input type="checkbox" id="C3">
<input type = "text" id = "E4" /><input type="checkbox" id="C4">
JS:
for (var i=1; i<=4; i++) {
if ("$C" +i.checked == true) {continue;}
...;
}
</script>
解决方案
continue
是用于实现此目的的正确关键字。我怀疑你的问题是这个if
陈述永远不会是真的。
我想你想要这个:
// Add 1 to index first and then concatenate with "#C" to create jQuery id selector
if ($('#C' + (i + 1)).is(':checked')) { continue; }
您if
上面的陈述在功能上等同于(选中时):
if ("$Ctrue" == true) { continue; }
$C和布尔值的字符串值连接在一起。
推荐阅读
- reactjs - Google Chrome 无法在桌面系统上检测到 PWA?
- javascript - 无法在 nodejs 12.14.0 上安装 ref-struct 模块
- vue.js - 如果 ref 值具有括号字符,如何访问 vuejs refs
- azure-active-directory - Azure Active Directory - 跨租户同步解决方案
- java - 使用 RelBuilder 构建 RelNode 时,有什么方法可以删除特定规则?
- r - order() 函数为 R 中的字符提供了错误的顺序
- etcd - POD崩溃时如何删除etcd键?
- c# - 将字符串数组转换为 If else 语句 C#
- mobile-application - Nativescript-vue 视频播放器加载完成回调不起作用
- c# - 模拟具有类型约束的泛型方法