请输入宝宝的姓氏和性别,我们将为您提供一个分数最高的建议名字列表。
男孩
女孩
function submitForm(event) {event.preventDefault();const surname = document.getElementById('surname').value;const gender = document.getElementById('gender').value;const results = document.getElementById('results');const resultsHeading = document.getElementById('results-heading');const resultList = document.getElementById('results-list');if (surname === '' || gender === '') {alert('请输入姓氏和性别!');return;}results.style.display = 'block';resultList.innerHTML = '';resultsHeading.innerText = `姓氏为 ${surname},性别为 ${gender} 的宝宝建议名字:`;// 这里假设我们已经有一个函数可以生成建议的宝宝名字和分数const suggestedNames = generateSuggestedNames(surname, gender);suggestedNames.forEach(name => {const resultItem = document.createElement('li');resultItem.classList.add('result-item');const resultItemName = document.createElement('span');resultItemName.classList.add('result-item__name');resultItemName.innerText = name.name;const resultItemScore = document.createElement('span');resultItemScore.classList.add('result-item__score');resultItemScore.innerText = name.score;resultItem.appendChild(resultItemName);resultItem.appendChild(resultItemScore);resultList.appendChild(resultItem);});}// 这里假设 generateSuggestedNames 是一个返回建议宝宝名字和分数的函数function generateSuggestedNames(surname, gender) {return [{name: '张浩',score: 95},{name: '李伟',score: 90},{name: '王丽',score: 85},{name: '赵明',score: 80},{name: '周阳',score: 75}];}