这是我第一次使用模态框,我无法在链接点击时打开我的模态框。我在控制台中没有收到任何错误,所以我很难解决这个问题。
HTML:
<!--Navbar-->
<nav class="navbar">
<div class="logo">
<h4>Earthquake Feed</h4>
</div>
<ul class="nav-links">
<li><a href="#simpleModal" data-target="simpleModal" data-toggle ="simpleModal" id="aboutModal">About</a></li>
<li><a href="#">Legend</a></li>
</ul>
</nav>
<!--About Modal-->
<div id="simpleModal" class="modal">
<div class="modal-content">
<span class="closeBtn">×</span>
<p>Hello....I am a modal</p>
</div>
</div>
Javascript:
// Get about modal element
var modal = document.getElementById('simpleModal');
// get open about modal link
var aboutModal = document.getElementById('aboutModal');
// Get close button
var closeBtn = document.getElementsByClassName('closeBtn')[0];
// listen for open/close click
aboutModal.addEventListener('click', openModal);
aboutModal.addEventListener('click', closeModal);
// opens and closes modal
function openModal(){
modal.style.display = 'block';
}
function closeModal(){
modal.style.display = 'none';
}
有什么建议?
慕姐4208626
慕田峪4524236
慕的地6264312
相关分类