橘子味阳光 2016-04-25 01:58 采纳率: 16.7%
浏览 1518
已采纳

jquery 选中 checkbox undefined

 "aoColumnDefs":
                 [
                   {'bVisible': false, 'aTargets': []},
                   {'bSortable': false, 'aTargets': []},
                 {
//                      "sTitle": "we",
//                      "sClass" :"center",
                        "sWidth": "10%",
                        "mData" : null,
                        "aTargets" : [ 0 ],
                        "mRender": function(data){
                            return "<input type='checkbox' name='productCheckbox' id='"+data.businessId+"' value='"+data.businessId+"'>";
                        }
                    }, 
  success: function(data){
                        console.log("checkboxselected============="+data.actConfg);
                        $(data.actConfg).each(function(i,item){
                            console.log("checkboxselected============="+item.businessId);

                            //$('input:checkbox').eq(0).attr("checked",'true');
                            $(":checkbox[value='22']").prop("checked",true);
                            $("input:checkbox[value='"+item.businessId+"']").attr('checked','true');
                            //$("input[id='"+item.businessId+"']:checkbox").attr("checked",true)
                            console.log("hhhhhhhhhhhhh=============");
                        });
                        }

操作不了动态生成的,静态直接写的可以为什么? $("input:checkbox[value='"+item.businessId+"']")这个取到的是undefined

  • 写回答

1条回答 默认 最新

  • danielinbiti 2016-04-25 02:10
    关注
     $("input:checkbox[value='"+item.businessId+"']").attr('checked','true');
     改成
     $("input:checkbox[value='"+item.businessId+"']").prop('checked','true');
    
     对于
      checked, selected 或者 disabled 使用prop()方法设置true和false
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退