注册 登录
编程论坛 JavaScript论坛

写一程序判断2008是否是闰年。

颜小培 发布于 2010-03-09 13:35, 2738 次点击
急用,帮帮忙...谢谢了
10 回复
#2
颜小培2010-03-09 13:59
<script language="javascript">
    var year=2008;
      if(year%4==0){
        document.write(year+"年是闰年");
      }else{
        document.write(year+"年不是闰年");
}
</script>
#3
aspic2010-03-09 17:30
你要清楚什么是闰年 应该就很简单了
#4
观星2010-03-16 08:58
闰年是能被4整除,且不能被100整除的年份,2000年就不闰年,2004年是闰年
#5
cnfarer2010-03-18 08:01
闰年是能被4整除,且不能被100整除的年份,或者能被400整除的年份
#6
xppxyy2010-03-26 15:07
恩版主解释的很好!
#7
cuinan1282010-04-01 13:41
第一次路過進來看看 有沒有什麽可以學習的
#8
h_uamin2010-04-07 15:17
<script language="javascript">
    function setid()
   
      {    var year=window.myform.page.value;
          if(year%4==0&&year%100!=0){
            document.write(year+"是闰年");
            }
        else{
            document.write(year+"不是闰年");
            }   
         
      }
</script>
<form name="myform" action="?" method="get">   
  <input type="text" name="page">
  <input type="submit" value="Go" class="bl" onClick="setid();">   
</form>
#9
学飞的小鸟2010-04-11 22:03
<script language="javascript">
    function setid()
   
      {    var year=window.myform.page.value;
          if((year%4==0&&year%100!=0)||(year%400==0))
            {
            document.write(year+"是闰年");
            }
        else{
            document.write(year+"不是闰年");
            }   
         
      }
</script>
<form name="myform" action="?" method="get">   
  <input type="text" name="page">
  <input type="submit" value="Go" class="bl" onClick="setid();">   
</form>
#10
努力加油2010-04-13 21:56
我想问一下 那个代码写成var year=document.myform.page.value是不是也可以 用写到最顶层window吗?
#11
xiaoyuechuan2010-04-23 03:53
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.
<html xmlns="http://www.
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>判断闰年</title>
</head>

<body><form action="" method="get" name="form1" id="form1">
  请输入年份:
  <label>
  <input name="nian" type="text" id="nian" size="4" maxlength="4" />
  </label>
  <label>
  <input type="button" name="Submit" value="是否闰年"  onclick="aaa()" />
  </label>
</form>

<script type="text/javascript">
//闰年:能被4整除不能被100整除;能被100整除也能被400整除.
function   aaa(){
      var  a=document.form1.nian.value;
      if(((a%4==0)&&(a%100!=0))||((a%100==0)&&(a%400==0)))
      {
      alert(a+"年是闰年");
      }
      else
      {
      alert(a+"年不是闰年")
      }

}
</script>
</body>
</html>
1