1、先绑定属性data-groupClassId
var span2 = '<span class="replaceBlue cursor" data-target="#myModalMember" data-toggle="modal" data-groupClassId="'+groupId+'" >成员管理</span>';
2、modal 弹出
一、 //成员管理 $('#myModalMember').on('show.bs.modal',function(event){ var groupClassId = $(event.relatedTarget).attr('data-groupClassId'); //获取id 后这里可以直接用 console.log(groupClassId); sercice(sUrl.selectGroupMemberInfo, function(data){ if(data.success){ var GroupMemberInfos = data.body.GroupMemberInfos; var str=''; if(GroupMemberInfos.length>0){ for(var i=0;i<GroupMemberInfos.length;i++){ var userName = GroupMemberInfos[i].userName; var courseCount = GroupMemberInfos[i].courseCount; var isMember = GroupMemberInfos[i].isMember; str+='<div class="clearfix item">'; str+= '<span class="pull-left">'+userName+'-'+courseCount+'节</span>'; str+= '<span class="pull-right">'; str+= '<input type="checkbox" id="awesome_'+i+'" onclick="checkBox(this)">'; str+= '<label for="awesome_'+i+'"></label>'; str+= '</span>'; str+='</div>'; } } $("#selectStu").html(str); } }, { "addressId" : storageAddressId, "token":token, "groupClassId":groupClassId }) }); 二、 //成员管理 $('#myModalMember').on('show.bs.modal',function(event){
var groupClassId = $(event.relatedTarget).attr('data-groupClassId') ; //获取 后这里可以直接用 //给此弹框绑定 后面函数可以直接用 $("#myModalMember").attr('data-groupClassId',groupClassId); abc();
}); function abc(){ var groupClassId = $("#myModalMember").attr('data-groupClassId',groupClassId); //获取弹框上的id sercice(sUrl.selectGroupMemberInfo, function(data){ if(data.success){ var GroupMemberInfos = data.body.GroupMemberInfos; var str=''; if(GroupMemberInfos.length>0){ for(var i=0;i<GroupMemberInfos.length;i++){ var userName = GroupMemberInfos[i].userName; var courseCount = GroupMemberInfos[i].courseCount; var isMember = GroupMemberInfos[i].isMember; str+='<div class="clearfix item">'; str+= '<span class="pull-left">'+userName+'-'+courseCount+'节</span>'; str+= '<span class="pull-right">'; str+= '<input type="checkbox" id="awesome_'+i+'" onclick="checkBox(this)">'; str+= '<label for="awesome_'+i+'"></label>'; str+= '</span>'; str+='</div>'; } } $("#selectStu").html(str); } }, { "addressId" : storageAddressId, "token":token, "groupClassId":groupClassId }) }