做了一個純前端的生肖查詢小工具,輸入年份就能立刻得到對應生肖,不需要任何後端與資料庫。

說真的,没有人会忘記自己屬什麼;但想知道任意年份出生的人屬什麼,總不能一個個去推算。把年份填進輸入框(例如 1986),按下查詢即可得到答案。
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>生肖查詢</title>
<style type="text/css">
td, body { font-size: 12px }
a:link { color: #000000; text-decoration: none }
a:visited { color: #000000; text-decoration: none }
a:active { color: blue; text-decoration: none }
a:hover { color: red; text-decoration: underline }
</style>
</head>
<body>
<p>目前位置>>首頁>實用查詢>生肖查詢</p>
<p align="center">
<form name="frm">
生於:
<input size="4" value="1986" name="inyear"> 年
<input onclick="getpet()" type="button" value="查看生肖">
屬:
<input size="3" name="birth">
</form>
</p>
</body>
</html>
這類工具的核心其實只有一件事:把年份對十二取餘,再對照生肖表。農曆新年與國曆元旦不重合,邊界年份會有一兩週的誤差,若要更精確,可再引入可查表的新年日期陣列做校正。使用者體驗上,記得在按 Enter 時也觸發查詢,並對非數字輸入做基本驗證。