根據(jù)出生日期自動(dòng)取得星座的js代碼
更新時(shí)間:2010年07月20日 00:55:48 作者:
最近這個(gè)項(xiàng)目需要注冊(cè)時(shí)用戶填寫出生日期,然后自動(dòng)取得星座,想想好像用后臺(tái)代碼太麻煩只好轉(zhuǎn)而使用JavaScript。
無奈啊~只怪讀書時(shí)沒有好好用功~看著JavaScript,一個(gè)頭頓時(shí)變成兩個(gè)。。。。。。。。
還好網(wǎng)絡(luò)提供了很好的資料庫~看了下,然后自己改了下,基本算能完成任務(wù)吧~寫下一份存檔,留待日后
function xingzuo() {
var start = 1901, date=document.getElementById("txtDay").value, month=document.getElementById("txtMonth").value;;
with (document.getElementById("txtXZ")){
if (month == 1 && date >=20 || month == 2 && date <=18) {value = "水瓶座";}
if (month == 1 && date > 31) {value = "Huh?";}
if (month == 2 && date >=19 || month == 3 && date <=20) {value = "雙魚座";}
if (month == 2 && date > 29) {value = "Say what?";}
if (month == 3 && date >=21 || month == 4 && date <=19) {value = "白羊座";}
if (month == 3 && date > 31) {value = "OK. Whatever.";}
if (month == 4 && date >=20 || month == 5 && date <=20) {value = "金牛座";}
if (month == 4 && date > 30) {value = "I'm soooo sorry!";}
if (month == 5 && date >=21 || month == 6 && date <=21) {value = "雙子座";}
if (month == 5 && date > 31) {value = "Umm ... no.";}
if (month == 6 && date >=22 || month == 7 && date <=22) {value = "巨蟹座";}
if (month == 6 && date > 30) {value = "Sorry.";}
if (month == 7 && date >=23 || month == 8 && date <=22) {value = "獅子座";}
if (month == 7 && date > 31) {value = "Excuse me?";}
if (month == 8 && date >=23 || month == 9 && date <=22) {value = "室女座";}
if (month == 8 && date > 31) {value = "Yeah. Right.";}
if (month == 9 && date >=23 || month == 10 && date <=22) {value = "天秤座";}
if (month == 9 && date > 30) {value = "Try Again.";}
if (month == 10 && date >=23 || month == 11 && date <=21) {value = "天蝎座";}
if (month == 10 && date > 31) {value = "Forget it!";}
if (month == 11 && date >=22 || month == 12 && date <=21) {value = "人馬座";}
if (month == 11 && date > 30) {value = "Invalid Date";}
if (month == 12 && date >=22 || month == 1 && date <=19) {value = "摩羯座";}
if (month == 12 && date > 31) {value = "No way!";}
}
}
還好網(wǎng)絡(luò)提供了很好的資料庫~看了下,然后自己改了下,基本算能完成任務(wù)吧~寫下一份存檔,留待日后
復(fù)制代碼 代碼如下:
function xingzuo() {
var start = 1901, date=document.getElementById("txtDay").value, month=document.getElementById("txtMonth").value;;
with (document.getElementById("txtXZ")){
if (month == 1 && date >=20 || month == 2 && date <=18) {value = "水瓶座";}
if (month == 1 && date > 31) {value = "Huh?";}
if (month == 2 && date >=19 || month == 3 && date <=20) {value = "雙魚座";}
if (month == 2 && date > 29) {value = "Say what?";}
if (month == 3 && date >=21 || month == 4 && date <=19) {value = "白羊座";}
if (month == 3 && date > 31) {value = "OK. Whatever.";}
if (month == 4 && date >=20 || month == 5 && date <=20) {value = "金牛座";}
if (month == 4 && date > 30) {value = "I'm soooo sorry!";}
if (month == 5 && date >=21 || month == 6 && date <=21) {value = "雙子座";}
if (month == 5 && date > 31) {value = "Umm ... no.";}
if (month == 6 && date >=22 || month == 7 && date <=22) {value = "巨蟹座";}
if (month == 6 && date > 30) {value = "Sorry.";}
if (month == 7 && date >=23 || month == 8 && date <=22) {value = "獅子座";}
if (month == 7 && date > 31) {value = "Excuse me?";}
if (month == 8 && date >=23 || month == 9 && date <=22) {value = "室女座";}
if (month == 8 && date > 31) {value = "Yeah. Right.";}
if (month == 9 && date >=23 || month == 10 && date <=22) {value = "天秤座";}
if (month == 9 && date > 30) {value = "Try Again.";}
if (month == 10 && date >=23 || month == 11 && date <=21) {value = "天蝎座";}
if (month == 10 && date > 31) {value = "Forget it!";}
if (month == 11 && date >=22 || month == 12 && date <=21) {value = "人馬座";}
if (month == 11 && date > 30) {value = "Invalid Date";}
if (month == 12 && date >=22 || month == 1 && date <=19) {value = "摩羯座";}
if (month == 12 && date > 31) {value = "No way!";}
}
}
您可能感興趣的文章:
- js中 計(jì)算兩個(gè)日期間的工作日的簡單實(shí)例
- js計(jì)算系統(tǒng)當(dāng)前日期是星期幾的方法
- javascript日期計(jì)算實(shí)例分析
- JavaScript計(jì)算兩個(gè)日期時(shí)間段內(nèi)日期的方法
- javaScript 計(jì)算兩個(gè)日期的天數(shù)相差(示例代碼)
- js根據(jù)給定的日期計(jì)算當(dāng)月有多少天實(shí)現(xiàn)思路及代碼
- 一個(gè)簡單的JavaScript 日期計(jì)算算法
- 用javascript實(shí)現(xiàn)計(jì)算兩個(gè)日期的間隔天數(shù)
- js根據(jù)日期判斷星座的示例代碼
- javascript計(jì)算星座屬相(十二生肖屬相)示例代碼
- JS根據(jù)生日月份和日期計(jì)算星座的簡單實(shí)現(xiàn)方法
相關(guān)文章
JavaScript手寫源碼之omit函數(shù)的實(shí)現(xiàn)
最近突然有個(gè)新的想法,想去看看前端的小庫來提升自己的編碼能力。但是又不知道怎么去證明自己是否真的看懂了,那就實(shí)現(xiàn)一個(gè)omit函數(shù)吧2023-02-02
js 判斷字符串中是否包含某個(gè)字符串的實(shí)現(xiàn)代碼
工作中經(jīng)常會(huì)使用到判斷一個(gè)字符串是否包含某一個(gè)字符串,因此總結(jié)一下幾個(gè)方法,需要的朋友可以參考下2023-03-03
uniapp微信小程序打卡功能的詳細(xì)實(shí)現(xiàn)流程
最近因?yàn)楣ぷ餍枰?搭建了一個(gè)加班打卡的小程序,下面這篇文章主要給大家介紹了關(guān)于uniapp微信小程序打卡功能的詳細(xì)實(shí)現(xiàn)流程,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-12-12
js實(shí)現(xiàn)的簡潔網(wǎng)頁滑動(dòng)tab菜單效果代碼
這篇文章主要介紹了js實(shí)現(xiàn)的簡潔網(wǎng)頁滑動(dòng)tab菜單效果代碼,可實(shí)現(xiàn)簡單的鼠標(biāo)滑過tab標(biāo)簽切換的功能,非常簡單實(shí)用,需要的朋友可以參考下2015-08-08
webpack-url-loader 解決項(xiàng)目中圖片打包路徑問題
這篇文章主要介紹了webpack-url-loader 解決項(xiàng)目中圖片打包路徑問題,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2019-02-02
uniapp路由uni-simple-router實(shí)例詳解
uni-simple-router專為uniapp打造的路由器,和uniapp深度集成,這篇文章主要給大家介紹了關(guān)于uniapp路由uni-simple-router的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-09-09
axios使用攔截器統(tǒng)一處理所有的http請(qǐng)求的方法
這篇文章主要介紹了axios使用攔截器統(tǒng)一處理所有的http請(qǐng)求的方法,通過一段實(shí)例代碼給大家介紹了axios攔截器使用,代碼簡單易懂,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2018-11-11
js使用split函數(shù)按照多個(gè)字符對(duì)字符串進(jìn)行分割的方法
這篇文章主要介紹了js使用split函數(shù)按照多個(gè)字符對(duì)字符串進(jìn)行分割的方法,實(shí)例分析了split函數(shù)的使用技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-03-03

