자바 스크립트에 대해 공부하려면 대괄호 도구를 사용하고 있습니다. 미리보기가 표시되면 버튼이 표시됩니다. 그러나 버튼을 여러 번 클릭하고 코드를 변경하더라도 아무 일도 일어나지 않습니다. 모달이 나타나지 않습니다. 모달에 관한 비슷한 질문이 많이 있다는 것을 알고 있습니다. 몇 가지 답변을 읽었지만이 문제를 해결할 수 없습니다. 누군가이 문제를 해결할 수있는 방법을 조언 해 줄 수 있습니까?자바 스크립트 모달이 작동하지 않습니다.
<!DOCTYPE html >
<html>
<head>
<link rel="stylesheet" href="modal.css">
</head>
<body>
<script type="text/javascript">
// Get the modal
var modal = document.getElementById('myModal');
// Get the button that opens the modal
var btn = document.getElementById("myBtn");
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
// When the user clicks on the button, open the modal
btn.onclick = function() {
modal.style.display = "block";
}
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
</script>
<!-- Trigger/Open The Modal -->
<button id="myBtn">Open Modal</button>
<!-- The Modal -->
<div id="myModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
<span class="close">x</span>
<p>Some text in the Modal..</p>
</div>
</div>
답 중 하나가 도움이 되었습니까? 아니면 아직도 붙어 있습니까? @ 카밀라 – JeremyS