jquery - jQuery:如何打开一个新的模态对话框或弹出窗口
问题描述
主页底部有一个登录按钮。当我点击按钮时,我想打开一个像另一个网页一样工作的新框架!但是弹出窗口应该在主页内打开并且位于主页的中心!它应该小于主页。
我一直在寻找的是如何打开新标签或新窗口。我想知道如何打开位于主页中心的弹出窗口。
解决方案
这是w3school.com的 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 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";
}
}
/* The Modal (background) */
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
padding-top: 100px; /* Location of the box */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}
/* Modal Content */
.modal-content {
background-color: #fefefe;
margin: auto;
padding: 20px;
border: 1px solid #888;
width: 80%;
}
/* The Close Button */
.close {
color: #aaaaaa;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: #000;
text-decoration: none;
cursor: pointer;
}
<!-- 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">×</span>
<p>Place Your Content Here ..</p>
</div>
</div>
推荐阅读
- ios - 如何在第二次从 iOS 的 xamarin 表单中的菜单按钮进入票务列表后使票务列表清晰?
- python - 从 Flask 的蓝图中删除全局应用程序引用
- c# - 由于 DateTime.AddSeconds,查找上一个蜡烛不起作用
- npm - 将 Google Cloud Functions 与 registry.npmjs.org 以外的注册表一起使用
- javascript - 将应用程序从 Angular 8 更新到 Angular 9 时出错
- amadeus - 静态数据查询 - 生产环境中的自助 Amadeus API
- python - 如何将 y 轴标签添加到 df.boxplot
- java - 尝试调用虚拟方法“android.hardware.Display.VirtualDisplay”
- laravel - Laravel - 请告知表名
- safari - Safari.plist 中“防止跨站点跟踪”的 plist 键是什么?