<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>判断闰年与否</title>
</head>
<body>
<script language="javascript" type="text/javascript">
function checkYear(){
var txtObjYear = document.all.txtYear;
var txtYear = txtObjYear.value();
if ((txtObjYear == null) || (txtObjYear.length < 1) || (txtObjYear <0 )){
window.alert("请在文本框输入正确的年份!");
txtObjYear.focus();
return;
}
if (isNaN(txtYear))//用户输入的不是值
{
window.alert("您输入的不是有效的数字!");
txtObjYear.focus();
return;
}
if (isLeapYear(txtYear))
window.alert(txtYear+"闰年!");
else
window.alert(txtYear+"不是闰年!");
}
function isLeapYear(yearVal){
if((yearVal % 100 == 0 ) && (yearVal % 400 == 0))
return true;
if(yearVal % 4 == 0)
return true;
return false;
}
</script>
<form action="#" name="frmYear">
<p>请输入当前年份:
<input name="txtYear" type="text" />
<p>点击判断是不是闰年:
<input type="button" value="submit" onclick="checkYear()" />
</form>
</body>
</html>