Q:请设计一个表单,该表单可以输入一个4位的整数(代表年份数字)。表单提交后可以判断用户输入的年份是否是一个闰年。如果是闰年,就输出“xxxx年是闰年”,否则就输出“xxxx不是闰年”,使用一个页面完成。
A:(涉及数据类型:运算符)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Year</title>
</head>
<body>
<form action="" method="post">
请输入年份:<input type="text" value="" name="year">
<input type="submit" value="计算结果"><br /> <!--按钮-->
</form>
</body>
</html>
<?php
if(isset($_POST['year']) )
{
$year = $_POST['year']; //年份
echo "<br>";
if( is_numeric($year))
{
if( $year % 4 == 0 && $year % 100 != 0 || $year % 400 == 0) //能否被整除
{
echo $year."是闰年"; //输出闰年
}
else
{
echo $year."不是闰年";
}
}
else //输入其他
{
echo "你没有正确输入年份!";
}
}
?>