chore: initial commit
This commit is contained in:
141
test-button.html
Normal file
141
test-button.html
Normal file
@@ -0,0 +1,141 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<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;
|
||||
padding: 20px;
|
||||
max-width: 800px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
.test-section {
|
||||
margin: 20px 0;
|
||||
padding: 20px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 5px;
|
||||
}
|
||||
button {
|
||||
margin: 10px;
|
||||
padding: 10px 20px;
|
||||
font-size: 16px;
|
||||
border: none;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.primary-btn {
|
||||
background: #3b82f6;
|
||||
color: white;
|
||||
}
|
||||
.primary-btn:hover {
|
||||
background: #2563eb;
|
||||
}
|
||||
.secondary-btn {
|
||||
background: #6b7280;
|
||||
color: white;
|
||||
}
|
||||
.secondary-btn:hover {
|
||||
background: #4b5563;
|
||||
}
|
||||
.log {
|
||||
background: #f3f4f6;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
font-family: monospace;
|
||||
white-space: pre-wrap;
|
||||
max-height: 200px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>按钮功能测试</h1>
|
||||
|
||||
<div class="test-section">
|
||||
<h2>1. 基本按钮测试</h2>
|
||||
<button class="primary-btn" onclick="log('基本按钮被点击')">测试按钮</button>
|
||||
<button class="secondary-btn" onclick="log('次要按钮被点击')">次要按钮</button>
|
||||
</div>
|
||||
|
||||
<div class="test-section">
|
||||
<h2>2. 事件监听测试</h2>
|
||||
<button id="event-btn" class="primary-btn">事件监听按钮</button>
|
||||
<button onclick="removeEventListenerTest()" class="secondary-btn">移除事件监听</button>
|
||||
</div>
|
||||
|
||||
<div class="test-section">
|
||||
<h2>3. 异步操作测试</h2>
|
||||
<button class="primary-btn" onclick="testAsyncOperation()">测试异步操作</button>
|
||||
<button class="secondary-btn" onclick="testPromise()">测试 Promise</button>
|
||||
</div>
|
||||
|
||||
<div class="test-section">
|
||||
<h2>4. 控制台日志</h2>
|
||||
<div id="log" class="log"></div>
|
||||
<button onclick="clearLog()" class="secondary-btn">清空日志</button>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
let logElement = document.getElementById('log');
|
||||
let eventCount = 0;
|
||||
|
||||
function log(message) {
|
||||
const timestamp = new Date().toLocaleTimeString();
|
||||
const logEntry = `[${timestamp}] ${message}\n`;
|
||||
logElement.textContent += logEntry;
|
||||
console.log(message);
|
||||
logElement.scrollTop = logElement.scrollHeight;
|
||||
}
|
||||
|
||||
function clearLog() {
|
||||
logElement.textContent = '';
|
||||
log('日志已清空');
|
||||
}
|
||||
|
||||
// 事件监听测试
|
||||
const eventBtn = document.getElementById('event-btn');
|
||||
function handleEventClick() {
|
||||
eventCount++;
|
||||
log(`事件监听按钮被点击 ${eventCount} 次`);
|
||||
}
|
||||
eventBtn.addEventListener('click', handleEventClick);
|
||||
|
||||
function removeEventListenerTest() {
|
||||
eventBtn.removeEventListener('click', handleEventClick);
|
||||
log('事件监听已移除');
|
||||
}
|
||||
|
||||
// 异步操作测试
|
||||
async function testAsyncOperation() {
|
||||
log('开始异步操作...');
|
||||
try {
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
log('异步操作完成');
|
||||
} catch (error) {
|
||||
log(`异步操作失败: ${error}`);
|
||||
}
|
||||
}
|
||||
|
||||
function testPromise() {
|
||||
log('开始 Promise 测试...');
|
||||
new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
if (Math.random() > 0.3) {
|
||||
resolve('成功');
|
||||
} else {
|
||||
reject('失败');
|
||||
}
|
||||
}, 500);
|
||||
})
|
||||
.then(result => log(`Promise 结果: ${result}`))
|
||||
.catch(error => log(`Promise 错误: ${error}`));
|
||||
}
|
||||
|
||||
// 初始日志
|
||||
log('页面加载完成');
|
||||
log('按钮功能测试已就绪');
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user