注册 登录
编程论坛 WEB前端(UI)

javaweb初学者一个小问题

wyh416 发布于 2022-04-07 16:55, 4207 次点击
<div class="item item2">
            <div class="sc">
                <table id="cb">
                    <tr class="t1">
                        <td style="width: 70px;"><input type="checkbox" name="" id="sca">全选</td>
                        <td style="width: 70px;"><input type="checkbox" name="" id="del">删除</td>
                        <td>商品图片</td>
                        <td>商品名</td>
                        <td style="width: 100px">商品价格</td>
                        <td>商品数量</td>
                        <td>总价</td>
                        <td style="width: 60px">结算</td>
                    </tr>

                    <c:forEach items="${cartItems}" var="cartItem">
                        <tr class="t2">
                            <td style="width: 60px;"><input type="checkbox" name="" id="bs"></td>
                            <td style="width: 60px;color: red"><a
                                    href="${sw}/DebateShopItemServlet?pid=${cartItem.pId}">删除</a></td>
                            <td><img src="${cartItem.shop.sPhoto}" alt=""></td>
                            <td style="color: blueviolet;">${cartItem.shop.sName}</td>
                            <td style="font-size: 16px">$${cartItem.price}</td>
                            <td style="position: relative">
                                <ul class="amount">
                                    <li style="float: left;"><a
                                            href="${sw}/DecrCartServlet?pid=${cartItem.pId}&uid=${cartItem.uId}">-</a>
                                    </li>
                                    <input type="text" value="${cartItem.amount}"
                                           style="width: 25px;height: 26px;float: left;text-align: center;border: none">
                                    <li style="float: left"><a
                                            href="${sw}/AddCartServlet?pid=${cartItem.pId}&uid=${cartItem.uId}">+</a>
                                    </li>
                                </ul>
                                <br>
                                <div style="margin-top: 35px;color: red;font-size: 13px"><c:if
                                        test="${cartItem.amount<2}">${ss}</c:if></div>
                            </td>
                            <td style="color: blue">总价:${cartItem.amount*cartItem.price}</td>
                            <td style="width: 60px">结算</td>
                        </tr>
                    </c:forEach>
                </table>


javaweb 制作了了一个商品购买网页购物车,在用户登录后,可以从数据库拿到该用户的所有购物车信息并且于页面中实现(已经实现)

现在的目的是通过点击全选旁边的这个复选框,使商品自己拥有的这个小复选框也勾选
    但是因为页面中的这些购物车信息,全是从数据库拿到数据后才在页面出现的(小的复选框也是在登陆后才显示的)
想通过Js拿到所有的小复选框,但是总是只能拿到第一个显示的购物车信息的复选框
???求问:因该怎样才能拿到所有的复选框?
1 回复
#2
apull2022-04-10 02:19
前端用jQuery,
$("#cb .t2").each()


<input type="checkbox" name="" id="bs"> 这里的name和id不合适,要有唯一性,不然后台无法获知你到底选了哪个。可以对应数据库中购物车信息中的id或商品id。
1