用css和js写一个提示框要求可以自定义提示框显示的内容和显示时间
HTML代码:
<div id="myAlert"></div>
CSS代码:
#myAlert {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
padding: 10px 20px;
border-radius: 5px;
background-color: #fff;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
display: none;
}
JavaScript代码:
function showAlert(message, timeout) {
var alertBox = document.getElementById("myAlert");
alertBox.innerHTML = message;
alertBox.style.display = "block";
setTimeout(function() {
alertBox.style.display = "none";
}, timeout);
}
使用方法:
showAlert("这是一个提示框", 3000); // 显示3秒后自动隐藏
``
原文地址: https://www.cveoy.top/t/topic/enc7 著作权归作者所有。请勿转载和采集!