Javascript 模态,一个脚本同一面
我有一个模式在我的网站上工作,但我想要一个更多的模式,但如何? 或者可以链接到工作代码以提供帮助Javascript 模态,一个脚本同一面,javascript,twitter-bootstrap-3,bootstrap-modal,Javascript,Twitter Bootstrap 3,Bootstrap Modal,我有一个模式在我的网站上工作,但我想要一个更多的模式,但如何? 或者可以链接到工作代码以提供帮助 <div id="glemsom" class="modal"> <!-- Modal content --> <div class="modal-content"> <div class="modal-header"> <span class="close">×</span>
<div id="glemsom" class="modal">
<!-- Modal content -->
<div class="modal-content">
<div class="modal-header">
<span class="close">×</span>
<h2>Glemt koden?</h2>
</div>
<div class="modal-body">
<p>Modal no 1</p>
</div>
&时代;
格雷姆特科登?
模式一
使用此脚本:
<script>
// Get the modal
var modal = document.getElementById('glemsom');
// Get the button that opens the modal
var btn = document.getElementById("glemtkoden");
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
// When the user clicks 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>
//获取模态
var modal=document.getElementById('glemsom');
//获取打开模式对话框的按钮
var btn=document.getElementById(“glemtkoden”);
//获取关闭模态的元素
var span=document.getElementsByClassName(“关闭”)[0];
//当用户单击该按钮时,打开模式对话框
btn.onclick=函数(){
modal.style.display=“块”;
}
//当用户单击(x)时,关闭模式对话框
span.onclick=函数(){
modal.style.display=“无”;
}
//当用户单击模式之外的任何位置时,将其关闭
window.onclick=函数(事件){
如果(event.target==模态){
modal.style.display=“无”;
}
}
如何在脚本的同一侧添加更多模式。为什么不复制第一个模式并分配另一个id?为什么要手动执行此操作?使用bootstrap,此功能内置,无需阅读以下脚本