[JQ權威指南]第十六天:刪除記錄時的提示效果,jq權威
1.當使用者單擊“刪除”按鈕時候,整個頁面背景類似關機效果,“刪除”提示框反白,使用者可以選擇“關閉”按鈕,或單擊“確定”或“取消”操作
2.刪除提示框一直置中顯示,無論頁面大小如何變化
3。如果對某條記錄打勾,當使用者單擊提示框中的確定按鈕時候,將在頁面中刪除該記錄,同時關閉提示框,頁面背景恢複正常。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head> <title>刪除記錄時的提示效果</title> <script type="text/javascript" src="Jscript/jquery-1.4.2-vsdoc.js"> </script> <script type="text/javascript" src="Jscript/jquery-1.4.2.js"> </script> <style type="text/css"> body{font-size:13px} .divShow{line-height:32px;height:32px;background-color:#eee;width:280px;padding-left:10px} .divShow span{padding-left:50px} .dialog{width:360px;border:solid 5px #666;position:absolute;display:none;z-index:101} .dialog .title{background-color:#fbaf15;padding:10px;color:#fff;font-weight:bold} .dialog .title img{float:right} .dialog .content{background-color:#fff;padding:25px;height:60px} .dialog .content img{float:left} .dialog .content span{float:left;padding-top:10px;padding-left:10px} .dialog .bottom{text-align:right;padding:10px 10px 10px 0px;background-color:#eee} .mask {width:100%;height:100%; background-color:#000;position:absolute; top:0px;left:0px;filter:alpha(opacity=30);display:none;z-index:100} .btn {border:#666 1px solid;padding:2px;width:65px; filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0,StartColorStr=#ffffff, EndColorStr=#ECE9D8);} </style> <script type="text/javascript"> $(function() { $("#Button1").click(function() { //註冊刪除按鈕點擊事件 $(".mask").show(); //顯示背景色 showDialog(); //設定提示對話方塊的Top與Left $(".dialog").show(); //顯示提示對話方塊 }) /* *根據當前頁面與捲軸位置,設定提示對話方塊的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 }); } $(window).resize(function() {//頁面視窗大小改變事件 if (!$(".dialog").is(":visible")) { return; } showDialog(); //設定提示對話方塊的Top與Left }); $(".title img").click(function() { //註冊關閉圖片點擊事件 $(".dialog").hide(); $(".mask").hide(); }) $("#Button3").click(function() {//註冊取消按鈕點擊事件 $(".dialog").hide(); $(".mask").hide(); }) $("#Button2").click(function() {//註冊確定按鈕點擊事件 $(".dialog").hide(); $(".mask").hide(); if ($("input:checked").length != 0) {//如果選擇了刪除行 $(".divShow").remove(); //刪除某行資料 } }) }) </script></head><body> <div class="divShow"> <input id="Checkbox1" type="checkbox" /> <a href="#">這是一條可刪除的記錄</a> <span> <input id="Button1" type="button" value="刪除" class="btn" /> </span> </div> <div class="mask"></div> <div class="dialog"> <div class="title"> <img src="Images/close.gif" alt="點擊可以關閉" />刪除時提示 </div> <div class="content"> <img src="Images/delete.jpg" alt="" /><span>您真的要刪除該條記錄嗎?</span> </div> <div class="bottom"> <input id="Button2" type="button" value="確定" class="btn"/> <input id="Button3" type="button" value="取消" class="btn"/> </div> </div></body></html>
著作權聲明:本文為博主原創文章,未經博主允許不得轉載。