以下是一个使用JavaScript编写的简单表白网页的源代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>表白网页</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #f0f0f0;
margin: 0;
}
.container {
text-align: center;
background: white;
padding: 2rem;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
.message {
font-size: 2em;
margin-bottom: 1rem;
}
button {
padding: 0.5rem 1rem;
font-size: 1em;
cursor: pointer;
}
</style>
</head>
<body>
<div class="container">
<div class="message" id="message">喜欢你</div>
<button onclick="changeMessage()">换一句</button>
</div>
<script>
const messages = [
"我喜欢你",
"爱你每一天",
"你是我心中的阳光",
"和你在一起真好"
];
function changeMessage() {
const randomIndex = Math.floor(Math.random() * messages.length);
document.getElementById('message').textContent = messages[randomIndex];
}
</script>
</body>
</html>希望这个示例能帮助你创建一个简单的表白网页!如果有更多具体问题,欢迎继续提问。
没有搜到相关的文章