Jquery prop()与change()冲突解决办法

本文介绍如何使用jQuery实现全选功能,并确保选中状态变更时能够正确触发change事件,以便更新相关数据。文中提供了具体的代码实例,包括对不同类型的输入框(如paxOdr、paxStand等)进行操作的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

解决方案:
添加change(),让它触发$(“input[type=’checkbox’]”).prop(‘checked’, true).change();

代码实例如下:

$("input[name='paxOdr']:checkbox").change(function(){
        console.log("paxOdr>>>>>>>>");
        var type = $("#applyMainType").val();
        var arip = $("#serviceAirp").val();
        if(opt!="'view'" && opt!="view"){
            var datas =getCheckDataList('paxStand');//获取改变之前的数据
            $("#paxStandList li").remove();
            initStandard('1', type, arip, $("#paxStandList"), 'pax','paxStand', 'paxOdr');
            $("input[name='paxStand']:checkbox").each(function(i){
                ob =  $.parseJSON($(this).val());
            $.each(datas,function(m){
                if(socVos[m].standId == ob.standId && socVos[m].serviceId == ob.serviceId &&socVos[m].id == ob.id){
                    $("input[name='paxStand']:checkbox")[i].checked=true;
                }
            });
        });
        }
    });

全选时添加change方法

if(value=='paxSerList')$("input[name=paxSer]:checkbox").prop("checked", true);
            if(value=='paxList')$("input[name=pax]:checkbox").prop("checked", true).change();
            if(value=='paxOdrList')$("input[name=paxOdr]:checkbox").prop("checked", true).change();
            if(value=='paxStandList')$("input[name=paxStand]:checkbox").prop("checked", true);
            if(value=='crewList')$("input[name=crew]:checkbox").prop("checked", true).change();
            if(value=='crewOdrList')$("input[name=crewOdr]:checkbox").prop("checked", true).change();
            if(value=='crewStandList')$("input[name=crewStand]:checkbox").prop("checked", true);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值