您可以使用以下代码示例来实现将按钮重定向到另一个页面并自动弹出模态框的功能:
HTML代码:
Redirect to another page and open modal
CSS代码(styles.css):
.modal {
display: none;
position: fixed;
z-index: 1;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgba(0,0,0,0.4);
}
.modal-content {
background-color: #fefefe;
margin: 15% auto;
padding: 20px;
border: 1px solid #888;
width: 80%;
}
.close {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: black;
text-decoration: none;
cursor: pointer;
}
JavaScript代码(script.js):
function redirectAndOpenModal() {
window.location.href = "anotherPage.html";
openModal();
}
function openModal() {
var modal = document.getElementById("myModal");
modal.style.display = "block";
}
function closeModal() {
var modal = document.getElementById("myModal");
modal.style.display = "none";
}
请注意,上述示例假设您有一个名为"anotherPage.html"的另一个页面,以及通过CSS定义的模态框样式。
上一篇:按钮移动不正确的原因是什么
下一篇:按钮隐藏/显示获取日期参数