fix: 使用 inline onclick 方式关闭模态框,更可靠

This commit is contained in:
2026-04-16 12:27:07 +08:00
parent 768b582db9
commit ffb06c2247
2 changed files with 10 additions and 12 deletions

View File

@@ -8,16 +8,14 @@ var refreshTimer = null;
document.addEventListener('DOMContentLoaded', function() {
loadConfig();
refreshAll();
});
// 点击模态框背景关闭
document.querySelectorAll('.modal').forEach(function(modal) {
modal.addEventListener('click', function(e) {
if (e.target === modal) {
modal.classList.remove('active');
function closeModalOnBackground(event, modalId) {
if (event.target.id === modalId) {
document.getElementById(modalId).classList.remove('active');
}
}
});
});
});
function loadConfig() {
fetch(API_BASE + '/api/config')

View File

@@ -156,8 +156,8 @@
</div>
<!-- 图片详情模态框 -->
<div class="modal" id="image-modal">
<div class="modal-content">
<div class="modal" id="image-modal" onclick="closeModalOnBackground(event, 'image-modal')">
<div class="modal-content" onclick="event.stopPropagation()">
<span class="modal-close" onclick="closeImageModal()">×</span>
<img id="modal-image" src="" alt="图片详情">
<div class="modal-info">
@@ -177,4 +177,4 @@
<script src="/static/app.js"></script>
</body>
</html>
</html>ml>