__("MON");?> -6ren">
gpt4 book ai didi

javascript - 如何检查多个复选框中是否至少选中了一个复选框?

转载 作者:可可西里 更新时间:2023-11-01 02:50:27 26 4
gpt4 key购买 nike

在我的表单中使用了很多复选框。我想检查是否至少选中了一个复选框。

<div id="sun">
<li><?php echo $this->__("SUN");?> </li>
<li><input class="allday" type="checkbox" name="availableday[Sunday][9-12]" value="9AM - 12AM"></li>
<li><input class="allday" type="checkbox" name="availableday[Sunday][12-6]" value="12PM - 6PM"></li>
<li><input class="allday" type="checkbox" name="availableday[Sunday][6-9]" value="6PM - 9PM"></li>
</div>
<div id="mon">
<li><?php echo $this->__("MON");?> </li>
<li><input class="allday" type="checkbox" name="availableday[Monday][9-12]" value="9AM - 12AM"></li>
<li><input class="allday" type="checkbox" name="availableday[Monday][12-6]" value="12PM - 6PM"></li>
<li><input class="allday" type="checkbox" name="availableday[Monday][6-9]" value="6PM - 9PM"></li>
</div>
<div id="tue">
<li><?php echo $this->__("TUE");?> </li>
<li><input class="allday" type="checkbox" name="availableday[Tuesday][9-12]" value="9AM - 12AM"></li>
<li><input class="allday" type="checkbox" name="availableday[Tuesday][12-6]" value="12PM - 6PM"></li>
<li><input class="allday" type="checkbox" name="availableday[Tuesday][6-9]" value="6PM - 9PM"></li>
</div>
<div id="wed">
<li><?php echo $this->__("WED");?> </li>
<li><input class="allday" type="checkbox" name="availableday[Wednesday][9-12]" value="9AM - 12AM"></li>
<li><input class="allday" type="checkbox" name="availableday[Wednesday][12-6]" value="12PM - 6PM"></li>
<li><input class="allday" type="checkbox" name="availableday[Wednesday][6-9]" value="6PM - 9PM"></li>
</div>

如何验证至少一个复选框被选中?

最佳答案

好吧,直截了当:

var isSomeAlldayCheckboxChecked = document
.querySelectorAll('input[type="checkbox"].allday')
.some(function (each) { return each.checked; });

关于javascript - 如何检查多个复选框中是否至少选中了一个复选框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30613791/

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