橘子味阳光 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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备