zoukankan      html  css  js  c++  java
  • js输入年份计算其生肖的方法

    方法一:

    <html>
    <head>
    <script>
    function yeart(){
    var now=new Date();
    var year=now.getFullYear();
    var ss=year-2008;//设定2008为初始年份
    var ssc=ss%12;
    var ssyear=new Array("子鼠","丑牛","寅虎","卯兔","辰龙","巳蛇","午马","未羊","申猴","酉鸡","戌狗","亥猪");
    document.write(year+"年\n"+ssyear[ssc]);
    }
    </script>
    </head>
    <body onLoad="yeart()">
    </body>
    </html>

    方法二:

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <meta name="keywords" content="站长,网页特效,js特效,广告代码,zzjs,zzjs.net,sky,www.zzjs.net,站长特效 网" />
    <meta name="description" content="www.zzjs.net,站长特效网,站长必备js特效及广告代码。大量高质量js特效,提供高质量广告代码下载,尽在站长特效网" />
    <title>输入你的出生年份,可以自动算出你的属相,sky整理收集,站长特效欢迎您。</title>
    </head>
    <body   bgcolor=#FFFFFF  >
    <a href="<#ZC_BLOG_HOST#>">站长特效网</a>,站长必备的高质量网页特效和广告代码。zzjs.net,站长js特效。<hr>
    <!--欢迎来到站长特效网,我们网站收集大量高质量js特效,提供许多广告代码下载,网址:www.zzjs.netzzjs@msn.com,用.net打造靓站-->
    <SCRIPT language=JavaScript>
    <!--
    function getpet () {
            var toyear = 1997;
            var birthyear = document.frm.inyear.value;
            var birthpet="Ox"
            x = (toyear - birthyear) % 12
            if ((x == 1) || (x == -11)) {
                birthpet="您属老鼠"      }
                else  {
                 if (x == 0)             {
                 birthpet="您属牛"           }
                 else  {
                  if ((x == 11) || (x == -1)) {
                  birthpet="您属老虎"          }
                  else  {
                   if ((x == 10) || (x == -2)) {
                   birthpet="您属兔子"         }
                   else  {
                    if ((x == 9) || (x == -3))  {
                    birthpet="您属龙"         }
                    else  {
                     if ((x == 8) || (x == -4))  {
                     birthpet="您属蛇"      }
                     else  {
                      if ((x == 7) || (x == -5))  {
                      birthpet="您属马"      }
                      else  {
                       if ((x == 6) || (x == -6))  {
                       birthpet="您属羊"      }
                       else  {
                        if ((x == 5) || (x == -7))  {
                        birthpet="您属猴"     }
                        else  {
                         if ((x == 4) || (x == -8))  {
                         birthpet="您属鸡"    }
                         else  {
                          if ((x == 3) || (x == -9))  {
                          birthpet="您属狗"        }
                          else  {
                           if ((x == 2) || (x == -10))  {
                           birthpet="您属猪"         }
                          }
                         }
                        }
                       }
                      }
                     }
                    }
                   }
                  }
                 }
                }
            document.frm.birth.value = birthpet;
    }
    </SCRIPT>
    <FORM name=frm>
    出生年份:<INPUT name=inyear size=4 value=1986> <BR><INPUT onclick=getpet() type=button value=看看属什么><INPUT name=birth size=9></FORM>
    </body>
    </html>

    方法三:(大概的计算方法)

    (年份+9)%12  =   1   :鼠 

                              =   2   :牛 

                               =   3   :虎

  • 相关阅读:
    ActiveForm
    phpstudy配置虚拟主机
    PHP 二分查找
    mysql group by 用法解析(详细)
    Linux(CentOS)下的apache服务器配置与管理
    ubuntu server sudo出现sudo:must be setuid root 完美解决办法
    VB连接MYSQL数据的方法
    mysql 远程登录及常用命令
    在eclipse上搭建Roku开发环境
    linux ps查进程 kill关闭进程
  • 原文地址:https://www.cnblogs.com/dearxinli/p/2854943.html
Copyright © 2011-2022 走看看