DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> jQuery入門知識 >> JQuery入門技巧 >> jQuery實現根據生日計算年齡 星座 生肖
jQuery實現根據生日計算年齡 星座 生肖
編輯:JQuery入門技巧     
<html>
<head>
 <title></title>
 <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>

 <script type="text/javascript">
 //根據輸入的生日自動獲取星座,生肖和年齡。
 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>

以上就是本文的全部內容,希望對大家有所幫助,謝謝對的支持!

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved