JS 判斷閏年

<html>
<head>
   <meta http-equiv="content-type" content="text/html;charset=gb2312">
   <title>判斷閏年</title>
   <script type="text/javascript" languge="javascript">
    //能被4整除且不能被100整除
    //或
    //能被100整除且能被400整除
    function isLeapYear(){
     var pYear=window.myForm.theYear.value;
     if(!isNaN(parseInt(pYear))){
      if((pYear%4==0 && pYear%100!=0)||(pYear%100==0 && pYear%400==0)){
       window.alert(pYear+"是閏年!");
      }else{
         window.alert(pYear+"不是閏年!");
      }
     }else{
      window.alert("請輸入正確年份!");
     }
       }
   </script>
</head>
<body>
   <form action="#" name="myForm" method="post">
    <p>請輸入要判斷閏年的年份:<p/>
    <input name="theYear" type="text">
    <input name="select" type="button" value="計算" onClick="isLeapYear()">
   </form>
</body>
</html>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章