星座查询器
根据阳历生日获取星座信息
此工具用于通过用户的出生日期(阳历)来确定其对应的星座,用户输入出生的月份和日子,系统将输出相应的星座信息,如果用户只知道阴历生日,工具还提供了阴历转公历的功能,帮助用户确定准确的星座。
1、基本查询:用户输入阳历的月份和日期,点击查询按钮即可显示对应的星座。
2、高级查询:用户输入阴历的月份和日期以及出生年份,点击查询按钮,系统会自动转换为阳历日期并显示对应的星座。
基本查询:
输入:4月20日
输出:金牛座(4月20日 5月20日)
高级查询:
输入:三月初三 1990年
转换后阳历日期:4月23日 1990年
输出:金牛座(4月20日 5月20日)
document.addEventListener("DOMContentLoaded", () => { const queryForm = document.getElementById('queryForm'); const resultDiv = document.getElementById('result'); queryForm.addEventListener('submit', (e) => { e.preventDefault(); const month = parseInt(document.getElementById('month').value, 10); const day = parseInt(document.getElementById('day').value, 10); const isSolar = document.getElementById('solar').checked; const chineseMonth = document.getElementById('chineseMonth').value; const chineseDay = document.getElementById('chineseDay').value; const year = parseInt(document.getElementById('year').value, 10); let zodiacSign; if (isSolar) { zodiacSign = getZodiacBySolar(month, day); } else { // Convert Chinese calendar to Solar calendar const solarDate = convertChineseToSolar(chineseMonth, chineseDay, year); if (solarDate) { const [solarMonth, solarDay] = solarDate.split('/').map(Number); zodiacSign = getZodiacBySolar(solarMonth, solarDay); } else { zodiacSign = "无法转换日期"; } } resultDiv.textContent =您的星座是:${zodiacSign}
; }); }); function getZodiacBySolar(month, day) { const zodiacDates = [ { sign: '摩羯座', start: [1, 20], end: [2, 18] }, { sign: '水瓶座', start: [2, 19], end: [3, 20] }, { sign: '双鱼座', start: [3, 21], end: [4, 19] }, { sign: '白羊座', start: [4, 20], end: [5, 20] }, { sign: '金牛座', start: [5, 21], end: [6, 20] }, { sign: '双子座', start: [6, 21], end: [7, 22] }, { sign: '巨蟹座', start: [7, 23], end: [8, 22] }, { sign: '狮子座', start: [8, 23], end: [9, 22] }, { sign: '处女座', start: [9, 23], end: [10, 22] }, { sign: '天秤座', start: [10, 23], end: [11, 21] }, { sign: '天蝎座', start: [11, 22], end: [12, 21] }, { sign: '射手座', start: [12, 22], end: [1, 19] }, ]; for (let i = 0; i < zodiacDates.length; i++) { const dateRange = zodiacDates[i]; if ((month === dateRange.start[0] && day >= dateRange.start[1]) || (month === dateRange.end[0] && day <= dateRange.end[1])) { return dateRange.sign; } else if (month > dateRange.start[0] && month < dateRange.end[0]) { return dateRange.sign; } } return '未知星座'; // Should never reach here if dates are valid } function convertChineseToSolar(chineseMonth, chineseDay, year) { // Dummy implementation for example purposes only // A proper implementation would require a Chinese calendar algorithm or library const solarDates = { '正月初十': '2/13', '二月初十': '3/13', '三月初十': '4/12', '四月初十': '5/12', '五月初十': '6/11', '六月初十': '7/10', '七月初十': '8/9', '八月初十': '9/8', '九月初十': '10/10', '十月初十': '11/9', '冬月初十': '12/9', '腊月初十': '1/8' }; return solarDates[${chineseMonth}${chineseDay}
] || null; }
这个星座查询器可以帮助用户通过阳历或阴历生日查询自己的星座,通过简单的表单输入,用户可以快速得到自己的星座信息,这对于对星座感兴趣的用户来说是一个非常有用的工具。