這個項目是一個簡單的互動式測驗應用程式,使用HTML、CSS和 JavaScript。它允許用戶回答多項選擇題、提交答案並獲得即時分數。該應用程式演示了 JavaScript 中的基本表單處理、動態內容更新和 DOM 操作。
quiz-app/ │-- index.html ← The HTML structure │-- styles.css ← The CSS styling └-- script.js ← The JavaScript logic
關鍵要素:
<form> <h3> ? <strong>CSS (styles.css)</strong> </h3> <p>The CSS file styles the quiz interface, making it visually appealing and responsive.</p> <p><strong>Key Styling Concepts:</strong></p>
button { background-color: #28a745; color: #fff; padding: 10px 15px; border: none; border-radius: 5px; cursor: pointer; } button:hover { background-color: #218838; }
關鍵概念:
document.getElementById('submit-btn').addEventListener('click', function() { const answers = { q1: 'Paris', q2: '4', q3: 'Blue' }; let score = 0; const form = document.getElementById('quiz-form'); if (form.q1.value === answers.q1) score++; if (form.q2.value === answers.q2) score++; if (form.q3.value === answers.q3) score++; document.getElementById('result').textContent = `You scored ${score} out of 3!`; });
HTML 表單與輸入:
CSS 樣式:
JavaScript 互動性:
quiz-app/ │-- index.html ← The HTML structure │-- styles.css ← The CSS styling └-- script.js ← The JavaScript logic
<form> <h3> ? <strong>CSS (styles.css)</strong> </h3> <p>The CSS file styles the quiz interface, making it visually appealing and responsive.</p> <p><strong>Key Styling Concepts:</strong></p>
button { background-color: #28a745; color: #fff; padding: 10px 15px; border: none; border-radius: 5px; cursor: pointer; } button:hover { background-color: #218838; }
以上是互動測驗應用程式的詳細內容。更多資訊請關注PHP中文網其他相關文章!