javascript計(jì)算星座屬相(十二生肖屬相)示例代碼
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function signs() {
var start = 1901, birthyear = document.zodiac.year.value, date=document.zodiac.date.value, month=document.zodiac.month.selectedIndex;
with (document.zodiac.sign){
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!";}
}
x = (start - birthyear) % 12
with (document.zodiac.csign){
if (x == 1 || x == -11) {value = "老鼠";}
if (x == 0) {value = "牛";}
if (x == 11 || x == -1) {value = "老虎";}
if (x == 10 || x == -2) {value = "兔子";}
if (x == 9 || x == -3) {value = "龍";}
if (x == 8 || x == -4) {value ="蛇";}
if (x == 7 || x == -5) {value = "馬";}
if (x == 6 || x == -6) {value = "羊";}
if (x == 5 || x == -7) {value = "猴子";}
if (x == 4 || x == -8) {value = "雞";}
if (x == 3 || x == -9) {value = "狗";}
if (x == 2 || x == -10) {value = "豬";}
}
}
// End -->
</script>
<form name="zodiac">
<center>
<table bgcolor="#eeaa00" border="2" bordercolor="#000000" rules="none" cellspacing="0" cellpadding="4">
<tr><td><b><i>出生年份</i></b></td>
<td><div align="right"><input type="text" size="10" name="year" value="出生年份" onClick=value=""></div></td>
<td><!--This empty field is just for appearance--></td>
<tr><td><b><i>出生月份</i></b></td>
<td><div align="right">
<select name="month">
<option value="x">請(qǐng)選擇一個(gè)月份</option>
<option value="1">一月</option><option value="2">二月</option><option value="3">三月</option>
<option value="4">四月</option><option value="5">五月</option><option value="6">六月</option>
<option value="7">七月</option><option value="8">八月</option><option value="9">九月</option>
<option value="10">十月</option><option value="11">十一月</option>
<option value="12">十二月</option></select></div></td>
<td><!--This empty field is just for appearance--></td></tr>
<tr><td><b><i>天</i></b></td>
<td><div align="right"><input type="text" name="date" value="天" size="3" onClick=value=""></td>
<td><input type="button" value="計(jì)算一下" onClick="signs()"></div></td></tr>
<tr><td><b><i>星座:</i></b></td>
<td><div align="right"><input type="text" name="sign" size="12" value="" align="right"></div></td></tr>
<td><!--This empty field is just for appearance--></td></tr>
<tr><td><b><i>屬相:</i></b></td>
<td><div align="right"><input type="text" name="csign" size="12"></div></td>
<td><!--This empty field is just for appearance--></td></tr>
</table>
</center>
</form>
相關(guān)文章
Postman參數(shù)化實(shí)現(xiàn)過程及原理解析
這篇文章主要介紹了Postman參數(shù)化實(shí)現(xiàn)過程及原理解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-08-08JavaScript實(shí)現(xiàn)檢查頁面上的廣告是否被AdBlock屏蔽了的方法
這篇文章主要介紹了JavaScript實(shí)現(xiàn)檢查頁面上的廣告是否被AdBlock屏蔽了的方法,其實(shí)就是利用JS檢測div的名稱和樣式名稱實(shí)現(xiàn),需要的朋友可以參考下2014-11-11JavaScript仿小米實(shí)現(xiàn)球體分解動(dòng)畫
用過小米手機(jī)的應(yīng)該見過它的垃圾清理ui界面吧,本文將利用JavaScript模擬這一界面實(shí)現(xiàn)球體分解動(dòng)畫,感興趣的小伙伴可以學(xué)習(xí)一下2022-06-06JavaScript+canvas實(shí)現(xiàn)框內(nèi)跳動(dòng)小球
這篇文章主要為大家詳細(xì)介紹了JavaScript+canvas實(shí)現(xiàn)框內(nèi)跳動(dòng)小球,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-04-04js如何去除數(shù)組中的empty?undefined空項(xiàng)
這篇文章主要介紹了js如何去除數(shù)組中的empty?undefined空項(xiàng),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-08-08符合W3C Web標(biāo)準(zhǔn)的圖片連續(xù)無間隙水平滾動(dòng)
很久以前就有這個(gè)問題,總是找不到通用的,或比較簡單的“圖片連續(xù)無間隙向左滾動(dòng),無間隙向右滾動(dòng),符合W3C Web標(biāo)準(zhǔn)”2008-06-06js實(shí)現(xiàn)div模擬模態(tài)對(duì)話框展現(xiàn)URL內(nèi)容
這篇文章主要介紹了js實(shí)現(xiàn)div模擬模態(tài)對(duì)話框展現(xiàn)URL內(nèi)容的功能,涉及javascript動(dòng)態(tài)操作頁面元素樣式與ajax調(diào)用的相關(guān)技巧,需要的朋友可以參考下2016-05-05JS中判斷JSON數(shù)據(jù)是否存在某字段的方法
這篇文章主要介紹了JS中如何判斷JSON數(shù)據(jù)是否存在某字段,需要的朋友可以參考下2014-03-03