jQuery實現(xiàn)根據(jù)生日計算年齡 星座 生肖
更新時間:2016年11月23日 10:18:50 作者:逆心
本篇文章主要是對利用jQuery實現(xiàn)根據(jù)生日計算年齡,星座,生肖的示例代碼進(jìn)行了介紹,需要的朋友可以過來參考下
<html> <head> <title></title> <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script> <script type="text/javascript"> //根據(jù)輸入的生日自動獲取星座,生肖和年齡。 var year = new Array("豬", "鼠", "牛", "虎", "兔", "龍", "蛇", "馬", "羊", "猴", "雞", "狗"); jQuery(function () { $("#Birthday").blur(function () { setTimeout(function () { var strHtml = ""; var date = new Date($("#Birthday").val().replace(/-/g, "/")); var con = getxingzuo(date.getMonth() + 1, date.getDate()); strHtml += "你的星座是:" + con; var zodiac = year[(parseInt(date.getFullYear()) + 9) % 12]; strHtml += "<br/>你的生肖是:" + zodiac; var Age = new Date().getFullYear() - date.getFullYear(); strHtml += "<br/>你的年齡是:" + Age; $("#div1").append(strHtml); }, 200); }) }) function getxingzuo(month, day) { var d = new Date(1999, month - 1, day, 0, 0, 0); var arr = []; arr.push(["魔羯座", new Date(1999, 0, 1, 0, 0, 0)]) arr.push(["水瓶座", new Date(1999, 0, 20, 0, 0, 0)]) arr.push(["雙魚座", new Date(1999, 1, 19, 0, 0, 0)]) arr.push(["牡羊座", new Date(1999, 2, 21, 0, 0, 0)]) arr.push(["金牛座", new Date(1999, 3, 21, 0, 0, 0)]) arr.push(["雙子座", new Date(1999, 4, 21, 0, 0, 0)]) arr.push(["巨蟹座", new Date(1999, 5, 22, 0, 0, 0)]) arr.push(["獅子座", new Date(1999, 6, 23, 0, 0, 0)]) arr.push(["處女座", new Date(1999, 7, 23, 0, 0, 0)]) arr.push(["天秤座", new Date(1999, 8, 23, 0, 0, 0)]) arr.push(["天蝎座", new Date(1999, 9, 23, 0, 0, 0)]) arr.push(["射手座", new Date(1999, 10, 22, 0, 0, 0)]) arr.push(["魔羯座", new Date(1999, 11, 22, 0, 0, 0)]) for (var i = arr.length - 1; i >= 0; i--) { if (d >= arr[i][1]) return arr[i][0]; } } </script> </head> <body> <div id="div1" style="width:200px;height:200px;"> <input type="text" id="Birthday" value="請輸入你的生日!" /> <input type="button" value="開始計算" /> </div> </body> </html>
以上就是本文的全部內(nèi)容,希望對大家有所幫助,謝謝對腳本之家的支持!
您可能感興趣的文章:
- 基于HTML+CSS,jQuery編寫的簡易計算器后續(xù)(添加了鍵盤監(jiān)聽)
- 一個簡單的jQuery計算器實現(xiàn)了連續(xù)計算功能
- jquery精度計算代碼 jquery指定精確小數(shù)位
- jQuery實現(xiàn)購物車計算價格功能的方法
- jQuery實現(xiàn)購物車多物品數(shù)量的加減+總價計算
- jQuery計算textarea中文字?jǐn)?shù)(剩余個數(shù))的小程序
- 基于jQuery的計算文本框字?jǐn)?shù)的代碼
- Jquery AJAX 用于計算點擊率(統(tǒng)計)
- js數(shù)值計算時使用parseInt進(jìn)行數(shù)據(jù)類型轉(zhuǎn)換(jquery)
- jQuery實現(xiàn)的簡單在線計算器功能
相關(guān)文章
jQuery實現(xiàn)可以控制圖片旋轉(zhuǎn)角度效果(附demo源碼下載)
這篇文章主要介紹了jQuery實現(xiàn)可以控制圖片旋轉(zhuǎn)角度效果,可實現(xiàn)通過下方的滑塊拖動控制圖片旋轉(zhuǎn)的功能,涉及jQuery操作頁面元素樣式動態(tài)變換的技巧,并附帶demo源碼供讀者下載,需要的朋友可以參考下2016-01-01jquery實現(xiàn)實時改變網(wǎng)頁字體大小、字體背景色和顏色的方法
這篇文章主要介紹了jquery實現(xiàn)實時改變網(wǎng)頁字體大小、字體背景色和顏色的方法,涉及jquery使用css方法動態(tài)操作頁面元素樣式的相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-08-08(jQuery,mootools,dojo)使用適合自己的編程別名命名
我們經(jīng)常用一些別名方法來使用自己喜歡的js 庫。學(xué)習(xí)javascript的朋友可以參考下。2010-09-09