代码描述:JavaScript判断闰年。JavaScript判断闰年
首先介绍一下什么样的年费算是一个闰年: 能被4整除且不能被100整除或者能被100整除且能被400整除的年费就是闰年。 代码实例如下:
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="author" content="http://www.51qianduan.com/" /> <title>51前端</title> <script> function isLeapYear(){ var pYear=document.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("请输入正确年份!"); } } window.onload=function(){ var bt=document.getElementById("bt"); bt.onclick=function(){isLeapYear()} } </script> </head> <body> <form action="#" name="myForm" method="post"> 请输入要判断闰年的年份: <input name="theYear" type="text" /> <input name="select" type="button" value="计算" id="bt" /> </form> </body> </html>
请绑定手机号,在继续操作
注意:只有绑定手机以后,才可使用网站全部功能