1. 程式人生 > 實用技巧 >jquery_模態對話方塊

jquery_模態對話方塊

<!DOCTYPE html>
<html lang="en">
<head>
<title>Title</title>
<meta charset="UTF-8">
<script src="jquery-3.5.1.js"></script>
<!--&lt;!&ndash; <script src="js_file01.js"></script>&ndash;&gt; 儘量放後body前邊-->

<style>

*{
margin: 0;
}

#div1{

position: fixed;
z-index: 1000;
top: 0;
left: 0;
width: 100%;
height: 800px;
background-color: #959da5;
}

#div2{
position: fixed;
z-index: 1001;
width: 100%;
/*height: 300px;*/
top: 0;
bottom: 0;
left: 0;
right: 0;
background-color: chartreuse;
opacity: 0.3;
}

#div3{
width: 300px;
height: 300px;
position: absolute;
z-index: 1002;
top: 50%;
left: 50%;
margin-top: -150px;
margin-left: -150px;
background-color: red;
}
/*隱藏*/
.hide{
display: none;
}

</style>

</head>
<body>

<div id="div1">
<input type="button" value="click" onclick="show(this)">
</div>

<div id="div2" class="div hide"></div>

<div id="div3" class="div hide">
<input type="button" value="cancel" onclick="cancel(this)">
</div>

<script>
    function show(self) {
$(self).parent().siblings().removeClass("hide")
}
    function cancel(self) {
$(self).parent().parent().children(".div").addClass("hide")
}
    // function show() {
// var el=document.getElementsByClassName("div");
// for (var i=0;i<el.length;i++){
// el[i].classList.remove("hide");
// }
// }


// function cancel() {
// var el=document.getElementsByClassName("div");
// for (var i=0;i<el.length;i++){
// el[i].classList.add("hide");
// }
// }

</script>

</body>
</html>