【前端】【HTML+CSS+JavaScript(JS)】判断闰年/平年的实现

效果:

在这里插入图片描述

代码:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>判断闰年/平年</title>
		<style type="text/css">
			*{
				border: 0px solid;
				text-align: center;
				font-family: "微软雅黑";
			}
			#b-box{
				margin-top: 200px;
				width: 450px;
				height: 240px;
				border-color: #FF5500;
				border-radius: 10px;
				border-width: 2px;
				margin-left: 525px;
			}
			.ln1,.ln2{
				display: inline-block;
				height: 50px;
			}
			.ln1 input{
				height: 30px;
				text-align: left;
				border-color: #FF5500;
				border-width: 2px;
				border-radius: 10px;
			}
			.ln2{
				margin-top: 25px;
				margin-left: 70px;
				margin-right: 70px;
				display: inline-block;
			
			}
			.ln2 input{
				width: 80px;
				height: 40px;
				border-radius: 10px;
			}
			.ln2 input:hover{
				color: aliceblue;
				background-color: #FF5500;
				cursor: pointer;
			}
			#tt{
				margin-top: 20px;
				font-size: 30px;
				margin-bottom: 30px;
				color: #464646;
			}
		</style>
		<script type="text/javascript">
			function estimate(){
				var year = parseInt(document.getElementById("year-res").value);
				var res = ( year%4 == 0 && year%100 != 0 || year%400==0 ) ? "是闰年" : "是平年";
				document.getElementById("year-res").value = year+ res;
			}
			function reset(){
				document.getElementById("year-res").value = "";
			}
		</script>
	</head>
	<body>
		<div id="b-box">
			<div id="tt">
				<label>判断闰年/平年</label>
			</div>
			<div class="ln1"><label>请输入一个年份:</label></div>
			<div class="ln1"><input type="text" id="year-res" value="" /></div>
			<br/>
			<!-- 不要忘记onclick -->
			<div class="ln2"><input type="button" value="判断" onclick="estimate()"/></div>
			<div class="ln2"><input type="button" value="重置" onclick="reset()"/></div>
		</div>
	</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

_小鹰

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值