Troubleshooting: Refresh the parent window after closing the modal window
Mobile
2023-12-16 23:25:05
views: null
Troubleshooting: Refresh the parent window after closing the modal window
1. Modal windows and non-modal windows
- Modality and non-modality are mainly reflected in whether to "block" the application.
- Modal: After the window pops up,Blocks the application's window, making it inoperable;
- Non-modal: Does not block the application's window, and the two can operate independently.
- After the dialog box is displayed
- Modal dialog box: Yescannot be used in the same programto operate other windows.
- Modeless dialog boxes can also operate on other windows of the same program.
2. Pop up modal window
2.1 Achieve results
- as follows:
2.2 Implementation code
2.2.1 Refresh the parent window
2.2.2 Complete code
- as follows:
<!DOCTYPE html>
<html>
<head>
<title>Modal Window Example</title>
<style>
.modal-overlay {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.5);
z-index: 999;
display: none;
}
.modal {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: #fff;
padding: 20px;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
z-index: 1000;
display: none;
width: 600px;
height: 620px;
}
.modal-close {
position: absolute;
top: 10px;
right: 10px;
cursor: pointer;
}
</style>
</head>
<body>
<button id="open-modal">弹出模态框</button>
<div class="modal-overlay"></div>
<div class="modal">
<span class="modal-close">×</span>
<h2>这是一个模态框</h2>
<p>模态框中的内容可以根据需要进行更改。</p>
</div>
<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
<script>
$(function() {
$('#open-modal').click(function() {
$('.modal-overlay').fadeIn();
$('.modal').fadeIn();
});
$('.modal-close, .modal-overlay').click(function() {
$('.modal-overlay').fadeOut();
$('.modal').fadeOut();
window.location.reload();
});
});
</script>
</body>
</html>
2.3 Reference
3. Other refresh the parent window (the modal window page and the parent window are not on the same page)
3.1 Implementation code
3.1.1 Core code
3.1.2 Refreshing multi-layer modal windows
- as follows:
3.2 Reference
Origin blog.csdn.net/suixinfeixiangfei/article/details/134797685