js 回调函数示列

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();
                    });
                }
          });
        
    }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值