<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>自动消失消息提示</title>
<style>
/* 样式可以根据需求自行定义 */
.message {
position: fixed;
top: 20px;
left: 50%;
transform: translateX(-50%);
padding: 10px 20px;
background-color: #4CAF50;
color: white;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0,0,0,0.2);
display: none;
}
</style>
</head>
<body>
<div class="message" id="messageBox"></div>
<button onclick="showMessage()">显示消息</button>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
function showMessage() {
var messageBox = $('#messageBox');
messageBox.text('这是一条自动消失的消息!');
messageBox.fadeIn();
setTimeout(function() {
messageBox.fadeOut();
}, 3000); // 3秒后自动消失
}
</script>
</body>
</html>