l文件中添加一個表單,用于用戶輸入出生年份。代碼如下:
```>
<label for="birth-year">請輸入出生年份:</label>putame="birth-year">it>>
2. 接下來,我們需要添加一些JavaScript代碼,用于計算用戶的屬相和星座。代碼如下:
<script>ction calculate() {ententById("birth-year").value;
var zodiacs = ["猴", "雞", "狗", "豬", "鼠", "牛", "虎", "兔", "龍", "蛇", "馬", "羊"];dex = (year - 4) % 12;dex];stellations = ["水瓶座", "雙魚座", "白羊座", "金牛座", "雙子座", "巨蟹座", "獅子座", "處女座", "天秤座", "天蝎座", "射手座", "摩羯座"];stellationIndex = ((year % 100) - 4) % 12;stellationstellationsstellationIndex];stellation);
}enttListeneritctiont) {ttDefault();
calculate();
});
</script>
3. 最后,我們將查詢結果顯示在頁面上。代碼如下:
<div id="result"></div>
修改calculate函數,將結果顯示在這個div中:
```ction calculate() {ententById("birth-year").value;
var zodiacs = ["猴", "雞", "狗", "豬", "鼠", "牛", "虎", "兔", "龍", "蛇", "馬", "羊"];dex = (year - 4) % 12;dex];stellations = ["水瓶座", "雙魚座", "白羊座", "金牛座", "雙子座", "巨蟹座", "獅子座", "處女座", "天秤座", "天蝎座", "射手座", "摩羯座"];stellationIndex = ((year % 100) - 4) % 12;stellationstellationsstellationIndex];ententByIdnerHTMLstellation;
至此,我們已經完成了一個簡單的屬相星座查詢頁面。用戶輸入出生年份,點擊查詢按鈕后,頁面會顯示用戶的屬相和星座。