1.
//弹层选择函数开始
$(".open_frame_select").click(function(){
var that = this;
open_frame_for_select(that,function(ids){
$.getJSON('/cmp/cates/getbyids.htm?ids='+ids,function(json){
console.log(json.data);
if(json!='undefined' && json.code==0){
if(json.data!='undefined' && typeof json.data=='object'){
if(json.data.length>0){
//循环开始,注意是jquery的each循环和普通的for循环不同,return 并不能退出循环
var CATE_SN = "";
var names = "";
$(json.data).each(function(index,item){
CATE_SN +=item.SN;
names += item.NAME;
});
var a = new Array();
a = ids.split(",");
if(a.length>1){
layer.msg("只能选择一个分类!");
return false;
}
$("#CATE_SN").val(CATE_SN);
$("#cates_name").val(names);
//循环结束
}
}
}
});
});
});
//弹层选择函数结束
2.
var open_frame_for_select = function(that,func){
var mutil = $(that).attr("data-mutil");//1 支持多选 0单选
if(mutil !='undefined' && mutil =='true'){
mutil = 1;
}else{
mutil = 0;
}
var w = $(that).attr("data-width");
if(w=='undefined' || w==''){w = "100%";}
var h = $(that).attr("data-height");
if(h=='undefined' || h==''){h = "100%";}
var url = $(that).attr("data-url");
if(url.indexOf("?") == -1){
url = url + "?";
}
url += '&_mutil='+mutil;
var title = $(that).attr("data-title");
if(title=='undefined' || title==''){
title = false;
}
//console.log("mutil="+mutil);
//多窗口模式,层叠置顶
layer.open({
type: 2 //此处以iframe举例
,title: title
,area: [w,h]
,shade: 0.6
,maxmin: true
,offset:'auto'
,content:url
,btn: ['选择','确定', '关闭']
,yes: function(index,layero){
var body = layer.getChildFrame('body', index);
var iframeWin = window[layero.find('iframe')[0]['name']]; //iframeWin.selectIds();
iframeWin.selectIds();
}
,btn2: function(layero, index){
//console.log("yes");
//console.log(layero);
//console.log(index);
var iframe = $(index).find("iframe")[0].contentWindow.document;
//$(iframe).document.getElementById("editForm")
//console.log("iframe="+iframe);
var chk_value = "";
/*$("input[name='box_info']:checked",iframe).each(function() {
chk_value += ","+$(this).val();
})
if(chk_value.length>0){
chk_value = chk_value.substring(1);
}*/
$("input[name='ids']", iframe).each(function() {
chk_value += "," + $(this).val();
})
if (chk_value.length > 0) {
chk_value = chk_value.substring(1);
}
func(chk_value);
layer.close(layero);
}
,btn3: function(){
layer.closeAll();
}
,zIndex: layer.zIndex //重点1
,success : function(layero,index) {
// console.log("success");
//layer.setTop(layero); //重点2
//console.log(layero);
var body = layer.getChildFrame('body', index);
body.on('click','.book',function(){
var id = $(this).attr("data-id");
func(id);
layer.closeAll();
});
}
});
}