利用js实现checkbox的单选功能

项目需求:

一、 调整原有“补货费用余额”字段调整为“补货费用余额(SBU)”,新增“补货费用余额(总部)”字段
这里写图片描述
备注:字段展示金额为总金额,后台按表单号对应金额
创建补货订单后,必须勾选费用池 才能添加产品 只能单选

实现:利用checkbox实现单选功能,不选择状态,隐藏添加产品按钮即可:

前台展示部分代码:

<#if position.org??  &&  orderForm.orderTypeCode == "CUST" && (!orderForm.giftType?? || orderForm.giftType == "1")>
                <tr>
                    <td class="right" width="120px;">补货费用余额(SBU):</td>
                    <td class="left">
                        ${bfee!'0'} 元
                    </td>

                    <td class="right" width="120px;">补货费用余额(总部):</td>
                    <td class="left">
                        ${bfee!'0'} 元
                    </td>
                </tr>
            </table>

            <div style="height:2px;line-height:2px;">&nbsp;&nbsp;&nbsp;</div>

            <!-- 产品信息 -->

            <div>
                <div class="right" id="addProduct" style="margin-bottom: 5px;">
                <#if bFlag=="N">
                    <input type="button" class="m-btn" id="selectProduct" value=" 添加产品 " />
                </#if>
                </div>
                <table id='Products'></table>
            </div>

            <div style="height:20px;line-height:20px;">&nbsp;&nbsp;&nbsp;</div>
            <#else>
            <tr>
                    <td class="right" width="120px;">补货费用余额(SBU):</td>
                    <td class="left">
                        ${bfee!'0'} 元&nbsp;&nbsp;<input type="checkbox" class="cbox" id="bfee_sbu" value="${bfee!''}" name="bfee_sbu" />
                    </td>

                    <td class="right" width="120px;">补货费用余额(总部):</td>
                    <td class="left">
                        ${bfee!'0'} 元&nbsp;&nbsp;<input type="checkbox" class="cbox" id="bfee_zb" value="${bfeee!''}" name="bfee_zb"/>
                    </td>
                </tr>
            </table>
            <div>
                <div class="right" id="addProduct" style="margin-bottom: 5px;display:none;">
                <#if bFlag=="N">
                    <input type="button" class="m-btn" id="selectProduct" value=" 添加产品 " />
                </#if>
                </div>
                <table id='Products'></table>
            </div>

            <div style="height:20px;line-height:20px;">&nbsp;&nbsp;&nbsp;</div>
            </#if>

JS控制部分:

$(document).ready(function(){  
     $(".cbox").click(function(){
         if($("#bfee_sbu").prop("checked")||$("#bfee_zb").prop("checked")){
            document.getElementById('addProduct').style.display="block";
            if($(this).prop("checked")) { 
                $(":checkbox[type=checkbox]").removeAttr("checked"); 
                $(this).prop("checked","true"); 
            }else{
            $(this).prop("checked","false").siblings().prop("checked","false");
            } 
        }else{
            document.getElementById('addProduct').style.display="none";
        }  
    });
});

大致就是这些 主要看js中控制。。。。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值