/** * Created by mac on 17/5/8. */ //获取url后面参数 function getQueryString(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); var r = window.location.search.substr(1).match(reg); if (r != null) return unescape(r[2]); return null; }; //弹窗 ;(function() { var Pop = function(config) { var _this_ = this; //默认配置 this.config = { width: "380px", header: "", content: "", buttons: null, footCustom: null }; //默认参数扩展 if(config && $.isPlainObject(config)) { $.extend(this.config, config) } this.body = $("body"); this.mask = $('
'); this.win = $('
'); this.title = $('
'); this.titleText = $(''); this.closed = $('x'); this.content = $('
'); this.footer = $('
'); this.create(); }; Pop.prototype = { create: function() { var _this_ = this; var config = this.config, body = this.body, mask = this.mask, win = this.win, title = this.title, titleText = this.titleText, closed = this.closed, content = this.content, footer = this.footer; //关闭事件 closed.click(function(){ _this_.close(); }) //添加title if(config.header != "" && typeof config.header != "string") { title.append(titleText.append(config.header)); title.append(closed); win.append(title); } else { title.append(titleText.html(config.header)); title.append(closed); win.append(title); } //添加内容 if(config.content != "" && typeof config.content != "string") { win.append(content.append(config.content)); } else { win.append(content.html(config.content)); } //添加底部 if(config.footCustom != null) { footer.append(footCustom); } else if(config.buttons != null) { $(config.buttons).each(function() { var type = this.type ? this.type : ""; var btnText = this.text; var callback = this.callback ? this.callback : null; var button = $("" + btnText + ""); if(callback) { button.click(function() { callback(); }); } else { button.click(function() { _this_.close(); }) } footer.append(button) }); } win.append(footer); if(config.width != "300px") { mask.append(win.width(config.width)); } else { mask.append(win); } mask.css("height", $(document).height()); body.append(mask); }, close: function() { this.mask.remove(); } } window.Pop = Pop; })(jQuery);