Js simple implementation of the deletion of records when the prompt effect
- 2020-03-30 00:43:19
- OfStack
style
jquery
HTML
<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>
jquery
<script type="text/javascript">
$(function() {
$("#Button1").click(function() { //Register delete button click event
$(".mask").show(); //Display background color
showDialog(); //Set the Top and Left of the prompt dialog box
$(".dialog").show(); //Displays the prompt dialog box
})
function showDialog() {
var objW = $(window); //The current window
var objC = $(".dialog"); //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();
//Calculates the left margin when the dialog box is centered
var left = sclL + (brsW - curW) / 2;
//Calculates the top margin when the dialog box is centered
var top = sclT + (brsH - curH) / 2;
//Set the location of the dialog on the page
objC.css({ "left": left, "top": top });
}
$(window).resize(function() {//Page window size change event
if (!$(".dialog").is(":visible")) {
return;
}
showDialog(); //Set the Top and Left of the prompt dialog box
});
$(".title img").click(function() { //Register to close the image click event
$(".dialog").hide();
$(".mask").hide();
})
$("#Button3").click(function() {//Register the cancel button click event
$(".dialog").hide();
$(".mask").hide();
})
$("#Button2").click(function() {//Register the ok button click event
$(".dialog").hide();
$(".mask").hide();
if ($("input:checked").length != 0) {//If delete row is selected
$(".divShow").remove(); //Deletes a row of data
}
})
})
</script>
HTML
<div class="divShow">
<input id="Checkbox1" type="checkbox" />
<a href="#"> This is a erasable record </a>
<span>
<input id="Button1" type="button" value=" delete " class="btn" />
</span>
</div>
<div class="mask"></div>
<div class="dialog">
<div class="title">
<img src="Images/close.gif" alt=" Click to close " /> Prompt for deletion
</div>
<div class="content">
<img src="Images/delete.jpg" alt="" /><span> Do you really want to delete this record? </span>
</div>
<div class="bottom">
<input id="Button2" type="button" value=" determine " class="btn"/>
<input id="Button3" type="button" value=" cancel " class="btn"/>
</div>
</div>