113 lines
3.3 KiB
HTML
113 lines
3.3 KiB
HTML
|
|
<!DOCTYPE html>
|
||
|
|
<html lang="zh">
|
||
|
|
<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;
|
||
|
|
line-height: 1.6;
|
||
|
|
margin: 0;
|
||
|
|
padding: 20px;
|
||
|
|
background-color: #f5f5f5;
|
||
|
|
}
|
||
|
|
.container {
|
||
|
|
max-width: 800px;
|
||
|
|
margin: 0 auto;
|
||
|
|
background-color: white;
|
||
|
|
padding: 20px;
|
||
|
|
border-radius: 10px;
|
||
|
|
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
|
||
|
|
}
|
||
|
|
h1 {
|
||
|
|
color: #333;
|
||
|
|
text-align: center;
|
||
|
|
margin-bottom: 30px;
|
||
|
|
}
|
||
|
|
.content-box {
|
||
|
|
margin: 20px 0;
|
||
|
|
padding: 15px;
|
||
|
|
border: 1px solid #ddd;
|
||
|
|
border-radius: 5px;
|
||
|
|
background-color: #fff;
|
||
|
|
}
|
||
|
|
button {
|
||
|
|
background-color: #4CAF50;
|
||
|
|
color: white;
|
||
|
|
padding: 10px 20px;
|
||
|
|
border: none;
|
||
|
|
border-radius: 5px;
|
||
|
|
cursor: pointer;
|
||
|
|
font-size: 16px;
|
||
|
|
display: block;
|
||
|
|
margin: 20px auto;
|
||
|
|
}
|
||
|
|
button:hover {
|
||
|
|
background-color: #45a049;
|
||
|
|
}
|
||
|
|
.random-number {
|
||
|
|
font-size: 24px;
|
||
|
|
text-align: center;
|
||
|
|
color: #2196F3;
|
||
|
|
margin: 20px 0;
|
||
|
|
}
|
||
|
|
.color-box {
|
||
|
|
width: 100px;
|
||
|
|
height: 100px;
|
||
|
|
margin: 20px auto;
|
||
|
|
border-radius: 5px;
|
||
|
|
transition: background-color 0.3s;
|
||
|
|
}
|
||
|
|
</style>
|
||
|
|
</head>
|
||
|
|
<body>
|
||
|
|
<div class="container">
|
||
|
|
<h1>随机内容生成器</h1>
|
||
|
|
|
||
|
|
<div class="content-box">
|
||
|
|
<h2>随机数字</h2>
|
||
|
|
<div class="random-number" id="randomNumber">点击按钮生成</div>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<div class="content-box">
|
||
|
|
<h2>随机颜色</h2>
|
||
|
|
<div class="color-box" id="colorBox"></div>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<div class="content-box">
|
||
|
|
<h2>随机文本</h2>
|
||
|
|
<p id="randomText">点击按钮生成随机文本</p>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<button onclick="generateRandomContent()">生成新内容</button>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<script>
|
||
|
|
const texts = [
|
||
|
|
"生活就像一盒巧克力,你永远不知道下一块是什么味道。",
|
||
|
|
"成功不是偶然的,而是日复一日的坚持。",
|
||
|
|
"每一个清晨都是新的开始,充满无限可能。",
|
||
|
|
"保持微笑,因为生活总是充满惊喜。",
|
||
|
|
"今天的努力是明天的收获。"
|
||
|
|
];
|
||
|
|
|
||
|
|
function generateRandomContent() {
|
||
|
|
// 生成随机数字
|
||
|
|
const randomNum = Math.floor(Math.random() * 1000);
|
||
|
|
document.getElementById('randomNumber').textContent = randomNum;
|
||
|
|
|
||
|
|
// 生成随机颜色
|
||
|
|
const randomColor = '#' + Math.floor(Math.random()*16777215).toString(16);
|
||
|
|
document.getElementById('colorBox').style.backgroundColor = randomColor;
|
||
|
|
|
||
|
|
// 生成随机文本
|
||
|
|
const randomText = texts[Math.floor(Math.random() * texts.length)];
|
||
|
|
document.getElementById('randomText').textContent = randomText;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 页面加载时生成一次随机内容
|
||
|
|
generateRandomContent();
|
||
|
|
</script>
|
||
|
|
</body>
|
||
|
|
</html>
|