qq_37727187 2022-11-21 12:22 采纳率: 89.8%
浏览 0
已结题

请问这种情况如何判断对应的check是否被选中

           <div class="weui-panel weui-panel_access">
            <div class="weui-panel__hd"><span>江苏蓝之蓝旗舰店</span><a href="javascript:;" class="wy-dele"></a></div>
            <div class="weui-panel__bd">
                <div class="weui-media-box_appmsg pd-10">
                    <div class="weui-media-box__hd check-w weui-cells_checkbox">
                        <label class="weui-check__label" for="cart-pto1">
                            <div class="weui-cell__hd cat-check">
                                <input type="checkbox" class="weui-check" name="cartpro" id="cart-pto1"><i class="weui-icon-checked" /></i>
                            </div>
                        </label>
                    </div>
                    <div class="weui-media-box__hd">
                        <a href="pro_info.html">
                            <img class="weui-media-box__thumb" src="../upload/pro3.jpg" alt=""></a>
                    </div>
                    <div class="weui-media-box__bd">
                        <h1 class="weui-media-box__desc"><a href="pro_info.html" class="ord-pro-link">蓝之蓝蓝色瓶装经典Q7浓香型白酒500ml52度高端纯粮食酒2瓶装包邮</a></h1>
                        <p class="weui-media-box__desc">规格:<span>红色</span><span>23</span></p>
                        <div class="clear">
                            <div class="wy-pro-pri fl">¥<em class="num font-15">10.00</em></div>
                            <div class="pro-amount fr">
                                <%--<div class="Spinner"></div>--%>
                                <div class="Spinner1">
                                    <a class="DisDe" href="javascript:void(0)">
                                        <i>-</i>
                                    </a>
                                    <input class="Amount" href="javascript:fun()" value="1" autocomplete="off" maxlength="3" />
                                    <a class="Increase" href="javascript:void(0)">
                                        <i>+</i>
                                    </a>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>


        <div class="weui-panel weui-panel_access">
            <div class="weui-panel__hd"><span>江苏蓝之蓝旗舰店</span><a href="javascript:;" class="wy-dele"></a></div>
            <div class="weui-panel__bd">
                <div class="weui-media-box_appmsg pd-10">
                    <div class="weui-media-box__hd check-w weui-cells_checkbox">
                        <label class="weui-check__label" for="cart-pto1">
                            <div class="weui-cell__hd cat-check">
                                <input type="checkbox" class="weui-check" name="cartpro" id="cart-pto1"><i class="weui-icon-checked" /></i>
                            </div>
                        </label>
                    </div>
                    <div class="weui-media-box__hd">
                        <a href="pro_info.html">
                            <img class="weui-media-box__thumb" src="../upload/pro3.jpg" alt=""></a>
                    </div>
                    <div class="weui-media-box__bd">
                        <h1 class="weui-media-box__desc"><a href="pro_info.html" class="ord-pro-link">蓝之蓝蓝色瓶装经典Q7浓香型白酒500ml52度高端纯粮食酒2瓶装包邮</a></h1>
                        <p class="weui-media-box__desc">规格:<span>红色</span><span>23</span></p>
                        <div class="clear">
                            <div class="wy-pro-pri fl">¥<em class="num font-15">20.00</em></div>
                            <div class="pro-amount fr">
                                <%--<div class="Spinner"></div>--%>
                                <div class="Spinner1">
                                    <a class="DisDe" href="javascript:void(0)">
                                        <i>-</i>
                                    </a>
                                    <input class="Amount" href="javascript:fun()" value="1" autocomplete="off" maxlength="3" />
                                    <a class="Increase" href="javascript:void(0)">
                                        <i>+</i>
                                    </a>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="weui-panel weui-panel_access">
            <div class="weui-panel__hd"><span>江苏蓝之蓝旗舰店</span><a href="javascript:;" class="wy-dele"></a></div>
            <div class="weui-panel__bd">
                <div class="weui-media-box_appmsg pd-10">
                    <div class="weui-media-box__hd check-w weui-cells_checkbox">
                        <label class="weui-check__label" for="cart-pto1">
                            <div class="weui-cell__hd cat-check">
                                <input type="checkbox" class="weui-check" name="cartpro" id="cart-pto1"><i class="weui-icon-checked" /></i>
                            </div>
                        </label>
                    </div>
                    <div class="weui-media-box__hd">
                        <a href="pro_info.html">
                            <img class="weui-media-box__thumb" src="../upload/pro3.jpg" alt=""></a>
                    </div>
                    <div class="weui-media-box__bd">
                        <h1 class="weui-media-box__desc"><a href="pro_info.html" class="ord-pro-link">蓝之蓝蓝色瓶装经典Q7浓香型白酒500ml52度高端纯粮食酒2瓶装包邮</a></h1>
                        <p class="weui-media-box__desc">规格:<span>红色</span><span>23</span></p>
                        <div class="clear">
                            <div class="wy-pro-pri fl">¥<em class="num font-15">30.00</em></div>
                            <div class="pro-amount fr">
                                <%--<div class="Spinner"></div>--%>
                                <div class="Spinner1">
                                    <a class="DisDe" href="javascript:void(0)">
                                        <i>-</i>
                                    </a>
                                    <input class="Amount" href="javascript:fun()" value="1" autocomplete="off" maxlength="3" />
                                    <a class="Increase" href="javascript:void(0)">
                                        <i>+</i>
                                    </a>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    <script>
        $('.Increase').click(function () {
            var preobj = $(this).parent();
            var a = Number(preobj.find('.Amount').eq(0).val());
            var num = Number(preobj.find('.Amount').eq(0).val()) + 1;//最开始的数值
            preobj.find('.Amount').eq(0).val(num);//改变input数值         
            var amount2 = Number(document.getElementById('zong1').innerHTML);
            var obj = $(this).parent().parent().parent().parent();
            var num1 = Number(obj.find('.Amount').eq(0).val());//最开始的数值
            var price = Number(obj.find('.num').eq(0).html());//对应的单价  
            //判断check是否选中
           //更改-号的class的名称

            var amount = (num1 - a) * price;//更改后的单价 * 数量       
            var amount1 = amount2 + amount; //最终点击需要增加的金额
            document.getElementById('zong1').innerHTML = amount1;
        });

   </script>

请问这种情况如何判断对应的check是否被选中并, 更改-号的class的名称

  • 写回答

4条回答 默认 最新

  • 一把编程的菜刀 2022-11-22 08:51
    关注

    关键代码如下:

    //判断check是否选中
                var index=$('.Increase').index(this);//获取当前点击的+号class的下标
                var objcheckbox=$('.weui-check').eq(index);//获取当前点击的+号对应的checkbox对象
                if(objcheckbox.attr("checked")===true){//对应的复选框是否选中
                    
                }
    

    融合进去如下:

    <script>
            $('.Increase').click(function () {
                var preobj = $(this).parent();
                var a = Number(preobj.find('.Amount').eq(0).val());
                var num = Number(preobj.find('.Amount').eq(0).val()) + 1;//最开始的数值
                preobj.find('.Amount').eq(0).val(num);//改变input数值         
                var amount2 = Number(document.getElementById('zong1').innerHTML);
                var obj = $(this).parent().parent().parent().parent();
                var num1 = Number(obj.find('.Amount').eq(0).val());//最开始的数值
                var price = Number(obj.find('.num').eq(0).html());//对应的单价  
                //判断check是否选中
                var index=$('.Increase').index(this);//获取当前点击的+号class的下标
                var objcheckbox=$('.weui-check').eq(index);//获取当前点击的+号对应的checkbox对象
                if(objcheckbox.attr("checked")===true){//对应的复选框是否选中
                    
                }
               //更改-号的class的名称
     
                var amount = (num1 - a) * price;//更改后的单价 * 数量       
                var amount1 = amount2 + amount; //最终点击需要增加的金额
                document.getElementById('zong1').innerHTML = amount1;
            });
       </script>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(3条)

报告相同问题?

问题事件

  • 系统已结题 12月1日
  • 已采纳回答 11月23日
  • 修改了问题 11月21日
  • 修改了问题 11月21日
  • 展开全部

悬赏问题

  • ¥15 关于#stm32#的问题:第一张图是发送数据代码,第二第三张图是接收数据并进行DAC转换的函数,若用串口一接收数据并进行DAC转换,主函数代码该怎么写
  • ¥20 hc130怎么读写内部flash存储信息
  • ¥15 Axure rp9注册与登录交互
  • ¥15 我下载图形界面重启完就变成这样了,打字也打不了,动也动不了,该怎么解决(操作系统-centos)
  • ¥15 VBA中在窗体中遍历所有checkbox控件,提取出被选中的checkbox的caption值
  • ¥15 在Ubuntu上有什么命令,或者是系统文件能告诉我链接nvme ssd的pcie槽位是不是支持热插拔功能?
  • ¥15 ansys license许可证问题
  • ¥20 QQ号和密码都能正常登录微信 QQ号和密码登录微信显示密码错误
  • ¥15 单片机RTOS Kernel与应用分离开发,Kernel如何调起应用?
  • ¥15 快手小店商家版APP怎么第三方APP跳转到指定用户聊天界面