弹出框html5 jquery
来源:互联网 发布:新淘宝店如何提高销量 编辑:程序博客网 时间:2024/06/01 20:12
弹出框框............
xcConfirm.js
/* * 使用说明: * window.wxc.Pop(popHtml, [type], [options]) * popHtml:html字符串 * type:window.wxc.xcConfirm.typeEnum集合中的元素 * options:扩展对象 * 用法: * 1. window.wxc.xcConfirm("我是弹窗<span>lalala</span>"); * 2. window.wxc.xcConfirm("成功","success"); * 3. window.wxc.xcConfirm("请输入","input",{onOk:function(){}}) * 4. window.wxc.xcConfirm("自定义",{title:"自定义"}) */(function($){window.wxc = window.wxc || {};window.wxc.xcConfirm = function(popHtml, type, options) { var btnType = window.wxc.xcConfirm.btnEnum;var eventType = window.wxc.xcConfirm.eventEnum;var popType = {info: {title: "信息",icon: "0 0",//蓝色ibtn: btnType.ok},success: {title: "成功",icon: "0 -48px",//绿色对勾btn: btnType.ok},error: {title: "错误",icon: "-48px -48px",//红色叉btn: btnType.ok},confirm: {title: "提示",icon: "-48px 0",//黄色问号btn: btnType.okcancel},warning: {title: "警告",icon: "0 -96px",//黄色叹号btn: btnType.okcancel},input: {title: "信息输入......",icon: "",btn: btnType.ok},custom: {title: "",icon: "",btn: btnType.ok}};var itype = type ? type instanceof Object ? type : popType[type] || {} : {};//格式化输入的参数:弹窗类型var config = $.extend(true, {//属性title: "", //自定义的标题icon: "", //图标btn: btnType.ok, //按钮,默认单按钮//事件onOk: $.noop,//点击确定的按钮回调onCancel: $.noop,//点击取消的按钮回调onClose: $.noop//弹窗关闭的回调,返回触发事件}, itype, options);var $txt = $("<p>").html(popHtml);//弹窗文本domvar $tt = $("<span>").addClass("tt").text(config.title);//标题var icon = config.icon;var $icon = icon ? $("<div>").addClass("bigIcon").css("backgroundPosition",icon) : "";var btn = config.btn;//按钮组生成参数var popId = creatPopId();//弹窗索引var $box = $("<div>").addClass("xcConfirm");//弹窗插件容器var $layer = $("<div>").addClass("xc_layer");//遮罩层var $popBox = $("<div>").addClass("popBox");//弹窗盒子var $ttBox = $("<div>").addClass("ttBox");//弹窗顶部区域var $txtBox = $("<div>").addClass("txtBox");//弹窗内容主体区var $btnArea = $("<div>").addClass("btnArea");//按钮区域var $ok = $("<a>").addClass("sgBtn").addClass("ok").text("确定");//确定按钮var $cancel = $("<a>").addClass("sgBtn").addClass("cancel").text("取消");//取消按钮var $input = $("<input>").addClass("inputBox");//输入框var $clsBtn = $("<a>").addClass("clsBtn");//关闭按钮//建立按钮映射关系var btns = {ok: $ok,cancel: $cancel};init();function init(){//处理特殊类型inputif(popType["input"] === itype){$txt.append($input);}creatDom();bind();}function creatDom(){$popBox.append($ttBox.append($clsBtn).append($tt)).append($txtBox.append($icon).append($txt)).append($btnArea.append(creatBtnGroup(btn)));$box.attr("id", popId).append($layer).append($popBox);$("body").append($box);}function bind(){//点击确认按钮$ok.click(doOk);//回车键触发确认按钮事件$(window).bind("keydown", function(e){if(e.keyCode == 13) {if($("#" + popId).length == 1){doOk();}}});//点击取消按钮$cancel.click(doCancel);//点击关闭按钮$clsBtn.click(doClose);}//确认按钮事件function doOk(){var $o = $(this);var v = $.trim($input.val());if ($input.is(":visible")) config.onOk(v); else config.onOk();$("#" + popId).remove(); config.onClose(eventType.ok);}//取消按钮事件function doCancel(){var $o = $(this);config.onCancel();$("#" + popId).remove(); config.onClose(eventType.cancel);}//关闭按钮事件function doClose(){$("#" + popId).remove();config.onClose(eventType.close);$(window).unbind("keydown");}//生成按钮组function creatBtnGroup(tp){var $bgp = $("<div>").addClass("btnGroup");$.each(btns, function(i, n){if( btnType[i] == (tp & btnType[i]) ){$bgp.append(n);}});return $bgp;}//重生popId,防止id重复function creatPopId(){var i = "pop_" + (new Date()).getTime()+parseInt(Math.random()*100000);//弹窗索引if($("#" + i).length > 0){return creatPopId();}else{return i;}}};//按钮类型window.wxc.xcConfirm.btnEnum = {ok: parseInt("0001",2), //确定按钮cancel: parseInt("0010",2), //取消按钮okcancel: parseInt("0011",2) //确定&&取消};//触发事件类型window.wxc.xcConfirm.eventEnum = {ok: 1,cancel: 2,close: 3};//弹窗类型window.wxc.xcConfirm.typeEnum = {info: "info",success: "success",error:"error",confirm: "confirm",warning: "warning",input: "input",custom: "custom"};})(jQuery);
下载地址
0 0
- 弹出框html5 jquery
- html5 右下角弹出 广告框
- jquery弹出框
- JQuery实现弹出框
- JQuery弹出框总结
- JQuery弹出框总结
- jQuery 弹出框插件
- jquery弹出框
- JQuery弹出框总结
- jquery之弹出框
- jquery pop弹出框
- JQuery 做弹出框
- jquery 右下角弹出框
- JQuery 悬浮弹出框
- jquery弹出提示框
- JQUERY弹出框
- jquery 弹出框
- js/jQuery弹出框
- Wamp安装redis扩展和window安装redis-service(此文只针对学习redis)
- iOS 解决页面按钮同时点击,同时触发问题 设置所有UIButton的ExclusiveTouch属性为YES
- Login with RMAN immediately fails with ORA-04031, ORA-06508
- Floyd-Warshall算法(有向图)
- SQL语句复习
- 弹出框html5 jquery
- Python自动化交易(1) 原理及所用到的库
- 学习IOS开发的顾虑
- Android牛逼开源项目分类汇总
- UbuntuServer12安装、mysql+tomcat部署
- 远程访问不了linux服务器下的mysql解决方法
- Yarn上运行spark-1.6.0
- Listview:Cannot add header view to list -- setAdapter has already been called
- Case of the Zeros and Ones