请作为一个顶级程序员与ui设计师帮我用JS和html和CSS写一个可以英语单词默写的网页每次跳一个单词
当然可以帮助您创建一个可以英语单词默写的网页。下面是一个使用JS、HTML和CSS编写的简单示例:
HTML部分(index.html):
<!DOCTYPE html>
<html>
<head>
<title>英语单词默写</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<h1>英语单词默写</h1>
<div id="word-container">
<h2 id="word">点击开始</h2>
</div>
<div id="input-container">
<input type="text" id="input" placeholder="输入单词" disabled>
<button id="check-btn" disabled>检查</button>
</div>
<script src="script.js"></script>
</body>
</html>
CSS部分(style.css):
body {
font-family: Arial, sans-serif;
text-align: center;
}
h1 {
margin-top: 50px;
}
#word-container {
margin-top: 50px;
}
#input-container {
margin-top: 20px;
}
input[type="text"] {
padding: 5px;
margin-right: 10px;
}
button {
padding: 5px 10px;
}
JavaScript部分(script.js):
const words = ['apple', 'banana', 'cat', 'dog', 'elephant'];
let currentIndex = 0;
const wordElement = document.getElementById('word');
const inputElement = document.getElementById('input');
const checkButton = document.getElementById('check-btn');
// 初始化页面
function initialize() {
wordElement.textContent = '点击开始';
inputElement.value = '';
inputElement.disabled = true;
checkButton.disabled = true;
checkButton.removeEventListener('click', checkWord);
wordElement.addEventListener('click', startQuiz);
}
// 开始默写
function startQuiz() {
currentIndex = 0;
wordElement.textContent = words[currentIndex];
inputElement.disabled = false;
checkButton.disabled = false;
checkButton.addEventListener('click', checkWord);
wordElement.removeEventListener('click', startQuiz);
}
// 检查单词
function checkWord() {
const userInput = inputElement.value.trim().toLowerCase();
const currentWord = words[currentIndex].toLowerCase();
if (userInput === currentWord) {
alert('回答正确!');
} else {
alert('回答错误!');
}
currentIndex++;
if (currentIndex < words.length) {
wordElement.textContent = words[currentIndex];
inputElement.value = '';
} else {
alert('已完成所有单词!');
initialize();
}
}
// 初始化页面
initialize();
这个示例中,我们使用一个字符串数组来保存要默写的英语单词。当用户点击“开始”时,第一个单词将显示在页面上。用户可以在输入框中输入他们的答案,然后点击“检查”按钮来检查答案是否正确。如果答案正确,会弹出一个提示框,然后显示下一个单词。如果所有单词都被默写完,会弹出一个提示框,并重新初始化页面。
希望这个示例能满足您的需求!如果有任何进一步的问题,请随时提问
原文地址: https://www.cveoy.top/t/topic/ixJ4 著作权归作者所有。请勿转载和采集!