gpt4 book ai didi

javascript - 如何获取表格中选中的复选框的总数

转载 作者:行者123 更新时间:2023-11-28 15:16:21 26 4
gpt4 key购买 nike

我的 html 页面的表格中有很多复选框。在提交按钮上我想检查检查的数量。最多允许 6 个。

即检查>=6,提交正确或错误

这是 html:

<table id="table-seatmapping">
<tbody>
<tr>
<!-- 1 st row -->
<td>
<div style="display:block;clear: both;float:left;">
<table class="table-seatting">
<tbody>
<tr>
<td class="seat">
<div class="seat-box male">
<div class="seat-no">01</div>
</div>
</td>
</tr>
<tr>
<td class="seat">
<div class="seat-box available">
<div class="seat-no">02</div>
<div class="seat-optn">
<input type="checkbox" class="b-seat" name="seatno" value="02">
</div>
</div>
</td>
</tr>
<tr>
<td class="empty"></td>
</tr>
<tr>
<td class="empty"></td>
</tr>
<tr>
<td class="seat">
<div class="seat-box available">
<div class="seat-no">03</div>
<div class="seat-optn">
<input type="checkbox" class="b-seat" name="seatno" value="03">
</div>
</div>
</td>
</tr>
<tr>
<td class="seat">
<div class="seat-box available">
<div class="seat-no">04</div>
<div class="seat-optn">
<input type="checkbox" class="b-seat" name="seatno" value="04">
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</td>
<!-- 1st row end -->
<!-- 2nd row -->
<td>
<div style="display:block;clear: both;float:left;">
<table class="table-seatting">
<tbody>
<tr>
<td class="seat">
<div class="seat-box available">
<div class="seat-no">05</div>
<div class="seat-optn">
<input type="checkbox" class="b-seat" name="seatno" value="05" price="236">
</div>
</div>
</td>
</tr>
<tr>
<td class="seat">
<div class="seat-box available">
<div class="seat-no">06</div>
<div class="seat-optn">
<input type="checkbox" class="b-seat" name="seatno" value="06" price="236">
</div>
</div>
</td>
</tr>
<tr>
<td class="empty"></td>
</tr>
<tr>
<td class="empty"></td>
</tr>
<tr>
<td class="seat">
<div class="seat-box available">
<div class="seat-no">07</div>
<div class="seat-optn">
<input type="checkbox" class="b-seat" name="seatno" value="07" price="236">
</div>
</div>
</td>
</tr>
<tr>
<td class="seat">
<div class="seat-box female">
<div class="seat-no">08</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</td>
<!-- 2nd row end -->
<!-- 3rd row -->
<td>
<div style="display:block;clear: both;float:left;">
<table class="table-seatting">
<tbody>
<tr>
<td class="seat">
<div class="seat-box male">
<div class="seat-no">09</div>
</div>
</td>
</tr>
<tr>
<td class="seat">
<div class="seat-box available">
<div class="seat-no">10</div>
<div class="seat-optn">
<input type="checkbox" class="b-seat" name="seatno" value="10" price="512">
</div>
</div>
</td>
</tr>
<tr>
<td class="empty"></td>
</tr>
<tr>
<td class="empty"></td>
</tr>
<tr>
<td class="seat">
<div class="seat-box available">
<div class="seat-no">11</div>
<div class="seat-optn">
<input type="checkbox" class="b-seat" name="seatno" value="11" price="512">
</div>
</div>
</div>
</td>
</tr>
<tr>
<td class="seat">
<div class="seat-box female">
<div class="seat-no">12</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</td>
<!-- 3rd row end -->
<!-- 4th -->
<td>
<div style="display:block;clear: both;float:left;">
<table class="table-seatting">
<tbody>
<tr>
<td class="seat">
<div class="seat-box male">
<div class="seat-no">13</div>
</div>
</td>
</tr>
<tr>
<td class="seat">
<div class="seat-box available">
<div class="seat-no">14</div>
<div class="seat-optn">
<input type="checkbox" class="b-seat" name="seatno" value="14" price="122">
</div>
</div>
</td>
</tr>
<tr>
<td class="empty"></td>
</tr>
<tr>
<td class="empty"></td>
</tr>
<tr>
<td class="seat">
<div class="seat-box available">
<div class="seat-no">15</div>
<div class="seat-optn">
<input type="checkbox" class="b-seat" name="seatno" value="15" price="441">
</div>
</div>
</td>
</tr>
<tr>
<td class="seat">
<div class="seat-box female">
<div class="seat-no">16</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</td>
<!-- 4th end -->
<!-- 5th -->
<td>
<div style="display:block;clear: both;float:left;">
<table class="table-seatting">
<tbody>
<tr>
<td class="seat">
<div class="seat-box male">
<div class="seat-no">17</div>
</div>
</td>
</tr>
<tr>
<td class="seat">
<div class="seat-box available">
<div class="seat-no">18</div>
<div class="seat-optn">
<input type="checkbox" class="b-seat" name="seatno" value="18" price="2141">
</div>
</div>
</td>
</tr>
<tr>
<td class="empty"></td>
</tr>
<tr>
<td class="empty"></td>
</tr>
<tr>
<td class="seat">
<div class="seat-box available">
<div class="seat-no">19</div>
<div class="seat-optn">
<input type="checkbox" class="b-seat" name="seatno" value="19" price="112">
</div>
</div>
</td>
</tr>
<tr>
<td class="seat">
<div class="seat-box female">
<div class="seat-no">20</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</td>
<!-- 5th end -->
<!-- 6 -->
<td>
<div style="display:block;clear: both;float:left;">
<table class="table-seatting">
<tbody>
<tr>
<td class="seat">
<div class="seat-box male">
<div class="seat-no">21</div>
</div>
</td>
</tr>
<tr>
<td class="seat">
<div class="seat-box available">
<div class="seat-no">22</div>
<div class="seat-optn">
<input type="checkbox" class="b-seat" name="seatno" value="22" price="223">
</div>
</div>
</td>
</tr>
<tr>
<td class="empty"></td>
</tr>
<tr>
<td class="empty"></td>
</tr>
<tr>
<td class="seat">
<div class="seat-box available">
<div class="seat-no">23</div>
<div class="seat-optn">
<input type="checkbox" class="b-seat" name="seatno" value="23" price="112">
</div>
</div>
</td>
</tr>
<tr>
<td class="seat">
<div class="seat-box female">
<div class="seat-no">24</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</td>
<!-- 6 end -->
<!-- 7 -->
<td>
<div style="display:block;clear: both;float:left;">
<table class="table-seatting">
<tbody>
<tr>
<td class="seat">
<div class="seat-box male">
<div class="seat-no">25</div>
</div>
</td>
</tr>
<tr>
<td class="seat">
<div class="seat-box available">
<div class="seat-no">26</div>
<div class="seat-optn">
<input type="checkbox" class="b-seat" name="seatno" value="26" price="112">
</div>
</div>
</td>
</tr>
<tr>
<td class="empty"></td>
</tr>
<tr>
<td class="empty"></td>
</tr>
<tr>
<td class="seat">
<div class="seat-box available">
<div class="seat-no">27</div>
<div class="seat-optn">
<input type="checkbox" class="b-seat" name="seatno" value="27" price="412">
</div>
</div>
</td>
</tr>
<tr>
<td class="seat">
<div class="seat-box female">
<div class="seat-no">28</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</td>
<!-- 7 end -->
<!-- 8 -->
<td>
<div style="display:block;clear: both;float:left;">
<table class="table-seatting">
<tbody>
<tr>
<td class="seat">
<div class="seat-box male">
<div class="seat-no">29</div>
</div>
</td>
</tr>
<tr>
<td class="seat">
<div class="seat-box available">
<div class="seat-no">30</div>
<div class="seat-optn">
<input type="checkbox" class="b-seat" name="seatno" value="30" price="112">
</div>
</div>
</td>
</tr>
<tr>
<td class="empty"></td>
</tr>
<tr>
<td class="empty"></td>
</tr>
<tr>
<td class="seat">
<div class="seat-box available">
<div class="seat-no">31</div>
<div class="seat-optn">
<input type="checkbox" class="b-seat" name="seatno" value="31" price="116">
</div>
</div>
</td>
</tr>
<tr>
<td class="seat">
<div class="seat-box female">
<div class="seat-no">32</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</td>
<!-- 8 end -->
<!-- 9 -->
<td>
<div style="display:block;clear: both;float:left;">
<table class="table-seatting">
<tbody>
<tr>
<td class="seat">
<div class="seat-box male">
<div class="seat-no">33</div>
</div>
</td>
</tr>
<tr>
<td class="seat">
<div class="seat-box available">
<div class="seat-no">34</div>
<div class="seat-optn">
<input type="checkbox" class="b-seat" name="seatno" value="34" price="223">
</div>
</div>
</td>
</tr>
<tr>
<td class="empty"></td>
</tr>
<tr>
<td class="empty"></td>
</tr>
<tr>
<td class="seat">
<div class="seat-box available">
<div class="seat-no">35</div>
<div class="seat-optn">
<input type="checkbox" class="b-seat" name="seatno" value="35" price="223">
</div>
</div>
</td>
</tr>
<tr>
<td class="seat">
<div class="seat-box female">
<div class="seat-no">36</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</td>
<!-- 9 end -->
<!-- 10 -->
<td>
<div style="display:block;clear: both;float:left;">
<table class="table-seatting">
<tbody>
<tr>
<td class="seat">
<div class="seat-box male">
<div class="seat-no">37</div>
</div>
</td>
</tr>
<tr>
<td class="seat">
<div class="seat-box available">
<div class="seat-no">38</div>
<div class="seat-optn">
<input type="checkbox" class="b-seat" name="seatno" value="38" price="223">
</div>
</div>
</td>
</tr>
<tr>
<td class="empty"></td>
</tr>
<tr>
<td class="empty"></td>
</tr>
<tr>
<td class="seat">
<div class="seat-box available">
<div class="seat-no">39</div>
<div class="seat-optn">
<input type="checkbox" class="b-seat" name="seatno" value="39" price="223">
</div>
</div>
</td>
</tr>
<tr>
<td class="seat">
<div class="seat-box female">
<div class="seat-no">40</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</td>
<!-- 10 end -->
<!-- 11 -->
<td>
<div style="display:block;clear: both;float:left;">
<table class="table-seatting">
<tbody>
<tr>
<td class="seat">
<div class="seat-box male">
<div class="seat-no">41</div>
</div>
</td>
</tr>
<tr>
<td class="seat">
<div class="seat-box available">
<div class="seat-no">42</div>
<div class="seat-optn">
<input type="checkbox" class="b-seat" name="seatno" value="42" price="223">
</div>
</div>
</td>
</tr>
<tr>
<td class="empty"></td>
</tr>
<tr>
<td class="empty"></td>
</tr>
<tr>
<td class="seat">
<div class="seat-box available">
<div class="seat-no">43</div>
<div class="seat-optn">
<input type="checkbox" class="b-seat" name="seatno" value="43" price="223">
</div>
</div>
</td>
</tr>
<tr>
<td class="seat">
<div class="seat-box female">
<div class="seat-no">44</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</td>
<!-- 11 end -->
</tr>
</tbody>
</table>

帮我解决;我尝试过,但返回 0。

$('#btnContinue').on('click', function () {
var totSeatcheck = $('table#table-seatmapping tbody tr').find('input[type=checkbox][name=seatno]:checked"]').length;
alert(totSeatcheck);
return false;
});

最佳答案

选择器错误。它包含额外的]。选择器引擎不会抛出错误,它只是返回空集合/集合,并且空集合上的 .length 返回 0。

find('input[type=checkbox][name=seatno]:checked"]')
^

使用

find(':checkbox[name="seatno"]:checked')

关于javascript - 如何获取表格中选中的复选框的总数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33733551/

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