index.html
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>判断闰年,平年</title>
<script src="first.js"> </script>
</head>
<body>
<input type="text" placeholder="请输入年份"id="text">
<input type="button" id="ok" value="确定">
<h1 id="result"></h1>
</body>
</html>
first.js
window.onload=one;//打开窗口,执行one
function one()
{
document.getElementById("ok").onclick=two; //鼠标点了id=ok后执行two
function two() //别忘了写函数名,与上面对应
{
a=document.getElementById("text").value;
if(a%4==0&&a%100!=0||a%400==0)
{
document.getElementById("result").innerHTML="this is a 闰年";//等于号,不要写成了("")
}
else
{
document.getElementById("result").innerHTML="this is a 平年";
}
}
}
效果图:
本文地址:http://liuyanzhao.com/3449.html
转载请注明