HTML小游戲源代碼
<!doctype html> <html> <head> <title>HTML小游戲</title> </head> <body> <h1>HTML小游戲</h1> <p>歡迎來到HTML小游戲!</p> <p>請回答以下問題:</p> <form> <label for="question1">1. HTML是什么縮寫?</label><br> <input type="text" id="question1" name="question1"><br> <label for="question2">2. HTML中用來定義標題的標簽是什么?</label><br> <input type="text" id="question2" name="question2"><br> <label for="question3">3. HTML中用來定義段落的標簽是什么?</label><br> <input type="text" id="question3" name="question3"><br> <button type="submit">提交答案</button> </form> <p id="result"></p> <script> const form = document.querySelector('form'); const result = document.querySelector('#result'); form.addEventListener('submit', e => { e.preventDefault(); const question1 = form.elements['question1'].value.toLowerCase(); const question2 = form.elements['question2'].value.toLowerCase(); const question3 = form.elements['question3'].value.toLowerCase(); if (question1 === 'hypertext markup language' && question2 === 'h1' && question3 === 'p') { result.textContent = '恭喜你,全部回答正確!'; } else { result.textContent = '很遺憾,您的答案有誤,請重新回答!'; } }); </script> </body> </html>