
弹出框html5 jquery
发布日期:2021-05-14 05:15:19
浏览次数:22
分类:精选文章
本文共 4172 字,大约阅读时间需要 13 分钟。
弹出框框............
xcConfirm.js
/* * 使用说明: * window.wxc.Pop(popHtml, [type], [options]) * popHtml:html字符串 * type:window.wxc.xcConfirm.typeEnum集合中的元素 * options:扩展对象 * 用法: * 1. window.wxc.xcConfirm("我是弹窗lalala"); * 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",//蓝色i btn: 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 = $("").html(popHtml);//弹窗文本dom var $tt = $("").addClass("tt").text(config.title);//标题 var icon = config.icon; var $icon = icon ? $("
").addClass("bigIcon").css("backgroundPosition",icon) : ""; var btn = config.btn;//按钮组生成参数 var popId = creatPopId();//弹窗索引 var $box = $("").addClass("xcConfirm");//弹窗插件容器 var $layer = $("").addClass("xc_layer");//遮罩层 var $popBox = $("").addClass("popBox");//弹窗盒子 var $ttBox = $("").addClass("ttBox");//弹窗顶部区域 var $txtBox = $("").addClass("txtBox");//弹窗内容主体区 var $btnArea = $("").addClass("btnArea");//按钮区域 var $ok = $(" ").addClass("sgBtn").addClass("ok").text("确定");//确定按钮 var $cancel = $(" ").addClass("sgBtn").addClass("cancel").text("取消");//取消按钮 var $input = $("").addClass("inputBox");//输入框 var $clsBtn = $(" ").addClass("clsBtn");//关闭按钮 //建立按钮映射关系 var btns = { ok: $ok, cancel: $cancel }; init(); function init(){ //处理特殊类型input if(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 = $("").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);
发表评论
最新留言
路过按个爪印,很不错,赞一个!
[***.219.124.196]2025年04月23日 19时46分53秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
Explore Optimization
2019-03-07
Kali Linux 内网渗透教程 - ARP欺骗攻击 | 超详细
2019-03-07
2020Java程序设计基础(华东交通大学)章节测试免费满分答案
2019-03-07
小程序之wx:request(转)
2019-03-07
解决数据库报ORA-02289:序列不存在错误
2019-03-07
map[]和map.at()取值之间的区别
2019-03-08
成功解决升级virtualenv报错问题
2019-03-08
【SQLI-Lab】靶场搭建
2019-03-08
Xception 设计进化
2019-03-08
【Bootstrap5】精细学习记录
2019-03-08
SkyWalking性能剖析
2019-03-08
LeetCode197.打家劫舍
2019-03-08
A simple problem HDU-2522 【数学技巧】
2019-03-08
487-3279 POJ-1022【前导0~思维漏洞】
2019-03-08
Struts2-从值栈获取list集合数据(三种方式)
2019-03-08
vscode中快速生成vue模板
2019-03-08
demo---购物车的多条记录保存(cookie)
2019-03-09
参考图像
2019-03-09