我們在天貓進行購物的時候,經(jīng)常會碰到單擊刪除按鈕或者登陸按鈕后,彈出對話框問你是否刪除或者彈出一個登陸對話框,并且我們也是可以看到我們之前頁面的信息,就是點擊不了,只有對對話框進行操作后才有相應的變化。截圖如下(以天貓為例)
復制代碼 代碼如下:
<!DOCTYPE html>
<html>
<head>
<title>遮罩彈出窗口</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link type="text/css" href="../css/delete.css">
<script type="text/javascript" src="../js/jquery-1.10.2.js"></script>
<script type="text/javascript" src="../js/delete.js"></script>
</head>
<body>
<div>
<input type="checkbox"> <a href="#">這是一條可以刪除的記錄</a>
<input type="button" value="刪除">
</div>
<div></div>
<div>
<div>
<img src="../images/delete.gif">
刪除時提示
</div>
<div>
<img src="../images/delete.gif">
<span>你真的要刪除這條記錄嗎?</span>
</div>
<div>
<input type="button" value="確定">
<input type="button" value="取消">
</div>
</div>
</body>
</html>
復制代碼 代碼如下:
@CHARSET "UTF-8";
*{
margin: 0px;
padding: 0px;
}
.divShow{
line-height: 32px;
height: 32px;
background-color: #eee;
width: 280px;
padding-left: 10px;
}
.dialog{
width: 360px;
border: 1px #666 solid;
position: absolute;
display: none;
z-index: 101;//保證該層在最上面顯示
}
.dialog .title{
background:#fbaf15;
padding: 10px;
color: #fff;
font-weight: bold;
}
.dialog .title img{
float:right;
}
.dialog .content{
background: #fff;
padding: 25px;
height: 60px;
}
.dialog .content img{
float: left;
}
.dialog .content span{
float: left;
padding: 10px;
}
.dialog .bottom{
text-align: right;
padding: 10 10 10 0;
background: #eee;
}
.mask{
width: 100%;
height: 100%;
background: #000;
position: absolute;
top: 0px;
left: 0px;
display: none;
z-index: 100;
}
.btn{
border: #666 1px solid;
width: 65px;
}
復制代碼 代碼如下:
$(function(){
//綁定刪除按鈕的觸發(fā)事件
$("#button1").click(function(){
$(".mask").css("opacity","0.3").show();
showDialog();
$(".dialog").show();
});
/*
* 根據(jù)當前頁面于滾動條的位置,設置提示對話框的TOP和left
*/
function showDialog(){
var objw=$(window);//當前窗口
var objc=$(".dialog");//當前對話框
var brsw=objw.width();
var brsh=objw.height();
var sclL=objw.scrollLeft();
var sclT=objw.scrollTop();
var curw=objc.width();
var curh=objc.height();
//計算對話框居中時的左邊距
var left=sclL+(brsw -curw)/2;
var top=sclT+(brsh-curh)/2;
//設置對話框居中
objc.css({"left":left,"top":top});
}
//當頁面窗口大小改變時觸發(fā)的事件
$(window).resize(function(){
if(!$(".dialog").is(":visible")){
return;
}
showDialog();
});
//注冊關閉圖片單擊事件
$(".title img").click(function(){
$(".dialog").hide();
$(".mask").hide();
});
//取消按鈕事件
$("#noOk").click(function(){
$(".dialog").hide();
$(".mask").hide();
});
//確定按鈕事假
$("#ok").click(function(){
$(".dialog").hide();
$(".mask").hide();
if($("input:checked").length !=0){
//注意過濾器選擇器中間不能存在空格$("input :checked")這樣是錯誤的
$(".divShow").remove();//刪除某條數(shù)據(jù)
}
});
});<span>
新聞熱點
疑難解答
圖片精選