jQuery制作弹出窗(模态框)

时间:2023-03-08 16:10:16

来源:(二少)在南极

##index.html

<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title></title>
<style type="text/css">
*{margin:0;padding:0;list-style-type:none;}
body{font:12px/180% Arial, Helvetica, sans-serif,"宋体";}
a,img{border:0;}
a{color:#5e5e5e;text-decoration:none;}
a:hover{color:#3366cc;text-decoration:underline;}
/* box */
.box{position:absolute;width:600px;left:50%;height:auto;z-index:100;background-color:#fff;border:1px #8FA4F5 solid;padding:1px;}
.box h2{height:25px;font-size:14px;background-color:#3366cc;position:relative;padding-left:10px;line-height:25px;color:#fff;}
.box h2 a{position:absolute;right:5px;font-size:12px;color:#fff;}
.box .mainlist{padding:10px;}
.box .mainlist li{height:24px;line-height:24px;}
.box .mainlist li span{margin:0 5px 0 0;font-family:"宋体";font-size:12px;font-weight:400;color:#ddd;}
#TB_overlayBG{background-color:#666;position:absolute;z-index:99;left:0;top:0;display:none;width:100%;height:100%;opacity:0.5;filter: alpha(opacity=50);-moz-opacity: 0.5;}
</style>
<script src="js/jquery-2.1.1.min.js" type="text/javascript" charset="utf-8"></script>

//自己引入jQuery文件
<!-- <script src="js/popup.js" type="text/javascript" charset="utf-8"></script> -->
<script type="text/javascript">
$(function() {

$(".showbox").click(function() {
$("#TB_overlayBG").css({
display: "block", height: $(document).height()
});
$(".box").css({
left: ($("body").width() - $(".box").width()) / 2 - 20 + "px",
top: ($(window).height() - $(".box").height()) / 2 + $(window).scrollTop() + "px",
display: "block"
});
});

$(".close").click(function() {
$("#TB_overlayBG").css("display", "none");
$(".box ").css("display", "none");
});

})
</script>
</head>
<body>
<p align="center" style="font-size:18px;font-family:微软雅黑;margin:100px;"><a href="javascript:void(0);" class="showbox">jquery制作点击按钮弹出层</a></p>

<div id="TB_overlayBG"></div>
<div class="box" style="display:none">
<h2>jquery 特效列表<a href="#" class="close">关闭</a></h2>
<div class="mainlist">
<ul>
<li><span>▪</span><a href="/jquery/items/2011-09-20/193.html" title="jquery 导航插件 一个动画导航下拉菜单Apycom软件的Java下拉菜单">jquery 导航插件 一个动画导航下拉菜单Apycom软件的Java下拉菜单</a></li>
<li><span>▪</span><a href="/jquery/items/2011-09-20/191.html" title="jquery soChange 切换插件 支持焦点图片切换 选项卡切换 带按钮与分页索引按钮切换">jquery soChange 切换插件 支持焦点图片切换 选项卡切换 带按钮与分页索引按钮切换</a></li>
<li><span>▪</span><a href="/jquery/items/2011-09-18/189.html" title="jquery 图片切换特效 鼠标点击左右按钮焦点图切换滚动">jquery 图片切换特效 鼠标点击左右按钮焦点图切换滚动</a></li>
<li><span>▪</span><a href="/jquery/items/2011-09-18/187.html" title="jquery 分享代码在线制作鼠标一键复制url路径功能与分享信息">jquery 分享代码在线制作鼠标一键复制url路径功能与分享信息</a></li>
<li><span>▪</span><a href="/jquery/items/2011-09-18/185.html" title="jquery 制作鼠标点击描点a标签返回顶部">jquery 制作鼠标点击描点a标签返回顶部</a></li>
</ul>
</div>
</div>
</body>
</html>

jQuery制作弹出窗(模态框)

##popup.js

(function() {
var ptype = 1;

function setcookie(cName, cExpires) {
var zbj_ad_pop_cookie_time;
try {
zbj_ad_pop_cookie_time = parseFloat(cExpires) * 1;
}
catch (e) {
zbj_ad_pop_cookie_time = 60 * 60;
}
if (isNaN(zbj_ad_pop_cookie_time))
zbj_ad_pop_cookie_time = 60 * 60;
var then = new Date();
then.setTime(then.getTime() + zbj_ad_pop_cookie_time * 1000);
document.cookie = cName + '=1;expires=' + then.toGMTString() + ';path=/;';
}

function upcookie(cname, ctime) {
setcookie(cname, ctime);
}

var state = 0;
; (function() {
var d = navigator.userAgent;
var a = {};
a.ver = {
ie: /MSIE/.test(d),
ie6: !/MSIE 7\.0/.test(d) && /MSIE 6\.0/.test(d) && !/MSIE 8\.0/.test(d),
tt: /TencentTraveler/.test(d),
i360: /360SE/.test(d),
sogo: /; SE/.test(d),
gg: window.google && window.chrome,
_v1: '<object id="p01" width="0" height="0" classid="CLSID:6BF5' + '2A52-394' + 'A-1' + '1D3-B15' + '3-00' + 'C04F' + '79FAA6"></object>',
_v2: '<object id="p02" style="position:absolute;left:1px;top:1px;width:1px;height:1px;" classid="clsid:2D' + '360201-FF' + 'F5-11' + 'd1-8D0' + '3-00A' + '0C95' + '9BC0A"></object>'
};
if (a.ver.ie || a.ver.tt) {
document.write(a.ver._v1); document.write(a.ver._v2);
}
a.fs = null; a.fdc = null; a.timeid = 0; a.first = 1; a.url = ''; a.w = 0; a.h = 0;
a.init = function() {
try {
if (typeof document.body.onclick == "function") {
a.fs = document.body.onclick; document.body.onclick = null
}
if (typeof document.onclick == "function") {
if (document.onclick.toString().indexOf('clickpp') < 0) {
a.fdc = document.onclick; document.onclick = function() {
a.clickpp(a.url, a.w, a.h)
}
}
}
} catch (q) { }
};
a.donepp = function(c, g) {
if (g == 1 && (!a.ver.i360 && a.ver.ie6)) return;
if (state) return;
try {
document.getElementById("p01").launchURL(c); state = 1; upcookie(zbj_ad_pop_cookie_name, zbj_ad_pop_cookie_time)
} catch (q) { }
};
a.clickpp = function(c, e, f) {
a.open(c, e, f); clearInterval(a.timeid); document.onclick = null;
if (typeof a.fdc == "function") try { document.onclick = a.fdc } catch (q) { }
if (typeof a.fs == "function") try { document.body.onclick = a.fs } catch (q) { }
}
a.open = function(c, e, f) {
if (state) return;
a.url = c; a.w = e; a.h = f;
if (a.timeid == 0) a.timeid = setInterval(a.init, 100);
var b = 'height=' + f + ',width=' + e + ',left=0,top=0,toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes';
var j = 'window.open("' + c + '", "_blank", "' + b + '")';
var m = null;
try { m = eval(j) } catch (q) { }
if (m && !(a.first && a.ver.gg)) {
if (ptype != -1) { m.focus(); } else { m.blur(); window.focus(); }
state = 1; upcookie(zbj_ad_pop_cookie_name, zbj_ad_pop_cookie_time);
if (typeof a.fs == "function") try { document.body.onclick = a.fs } catch (q) { }
clearInterval(a.timeid);
} else {
var i = this, j = false;
if (a.ver.ie || a.ver.tt) {
document.getElementById("p01"); document.getElementById("p02");
setTimeout(function() {
var obj = document.getElementById("p02");
if (state || !obj) return;
try {
var wPop = obj.DOM.Script.open(c, "_blank", b);
if (wPop) {
if (ptype != -1) { wPop.focus(); } else { wPop.blur(); window.focus(); }
state = 1; upcookie(zbj_ad_pop_cookie_name, zbj_ad_pop_cookie_time);
} else if (a.ver.sogo) { state = 1; upcookie(zbj_ad_pop_cookie_name, zbj_ad_pop_cookie_time); }
} catch (q) { }
}, 200);
}
if (a.first) {
a.first = 0;
try { if (typeof document.onclick == "function") a.fdc = document.onclick } catch (p) { }
document.onclick = function() { i.clickpp(c, e, f) };
if (a.ver.ie) {
if (window.attachEvent) window.attachEvent("onload", function() { i.donepp(c, 1); });
else if (window.addEventListener) window.addEventListener("load", function() { i.donepp(c, 1); }, true);
else window.onload = function() { i.donepp(c, 1); };
}
}
}
};
a.getCookie = function(name) {
var cookie = document.cookie;
if (!name) {
return cookie;
} else {
var pattern = "(?:; )?" + name + "=([^;]*);?";
var rege = new RegExp(pattern);
if (rege.test(cookie)) {
return decodeURIComponent(RegExp["$1"]);
}
}
};
window.zbj_ad_pop = a;
})();
})();
var zbj_ad_pop_cookie_name = "zbj_ad_pop_cookie_name";
var zbj_ad_pop_cookie_time = 18 * 3600;
if (!zbj_ad_pop.getCookie(zbj_ad_pop_cookie_name)) {
zbj_ad_pop.open("", window.screen.width, window.screen.height, "alwaysLowered");
}

模态框,即弹窗,里面有三层,设置id和class,都是使用div框架层级,最外层是model-dialog,中间的为model-content,里面为内容,再往下就是可以同级存在,model-header,model-body等等,弹窗点击关闭图标为span,里面内容$times,删除的class后加上date-taggle等于模态的class,date-target等于删除的id,删除按钮中加上data-dismiss等于model可以关闭弹窗,
当想删除信息的时候,可以在vue的data中设置一个当前下标的属性为-1,然后在删除按钮中绑定v-on的点击时间,赋值为当前下标:index(user.index为用户序号),
在methods中写的方法为this.users.splice(this.当前下标,1),即从指定当前位置开始删除,
想删除所有了,就把点击事件赋值让它等于-1,再在方法里面加入if判断,如果是等于-1就赋值一个空数组,不然就用刚刚的方法,
想要弹窗弹出不同提示框的信息可以再加一个提示框,用v-show进行判断