我使用支架工具来研究JavaScript。 当我看到预览时,我可以看到一个按钮。但是,即使我多次单击该按钮并更改了代码,也不会发生任何事情。莫代尔没有出现。 我知道有这么多关于模态的类似问题。 我读了一些答案,但我无法解决这个问题。 有人可以请我给我建议我怎么能解决这个问题?JavaScript模式不起作用
<!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>
答案都有帮助吗?还是你仍然坚持? @camila – JeremyS