const result = document.querySelector('.result');const resultTitle = result.querySelector('.result-title');const resultList = result.querySelector('.result-list');const form = document.querySelector('.main-form');form.addEventListener('submit', (e) => {e.preventDefault();const name = e.target.querySelector('input[name="name"]').value;const birthday = e.target.querySelector('input[name="birthday"]').value;// 处理八字const birthdayArr = birthday.split(' ');const birthdayDate = birthdayArr[0].split('-');const birthdayTime = birthdayArr[1].split(':');const year = parseInt(birthdayDate[0]);const month = parseInt(birthdayDate[1]);const day = parseInt(birthdayDate[2]);const hour = parseInt(birthdayTime[0]);const minute = parseInt(birthdayTime[1]);// 计算生辰八字const bazi = [];bazi[0] = year % 10;bazi[1] = year / 10 % 10;bazi[2] = month % 10;bazi[3] = month / 10 % 10;bazi[4] = day % 10;bazi[5] = day / 10 % 10;bazi[6] = hour % 10;bazi[7] = hour / 10 % 10;// 计算五行const wuxing = ['金', '木', '水', '火', '土'];const wuxingCount = [0, 0, 0, 0, 0];for (let i = 0; i < bazi.length; i++) {switch (bazi[i]) {case 0:case 5:case 10:wuxingCount[0]++;break;case 1:case 6:case 11:wuxingCount[1]++;break;case 2:case 7:case 12:wuxingCount[2]++;break;case 3:case 8:case 13:wuxingCount[3]++;break;case 4:case 9:case 14:wuxingCount[4]++;break;}}// 根据五行起名let nameSuggestions = [];const dominantElement = wuxing[wuxingCount.indexOf(Math.max(...wuxingCount))];switch (dominantElement) {case '金':nameSuggestions = ['鑫', '锋', '锐', '刚', '铁'];break;case '木':nameSuggestions = ['林', '森', '浩', '青', '松'];break;case '水':nameSuggestions = ['淼', '涵', '清', '波', '澜'];break;case '火':nameSuggestions = ['焱', '炎', '辉', '烈', '明'];break;case '土':nameSuggestions = ['坤', '厚', '磊', '岩', '山'];break;}// 显示结果resultTitle.innerHTML = `根据八字五行,推荐的宝宝姓名:`;resultList.innerHTML = '';for (let i = 0; i < nameSuggestions.length; i++) {const li = document.createElement('li');li.innerHTML = `${nameSuggestions[i]}${name}`;resultList.appendChild(li);}result.style.display = 'block';});