【发布时间】:2022-09-26 15:23:59
【问题描述】:
基本上我创建了一个闰年计算器,但为了改善用户体验,我希望它在网页上显示一条消息,确认输入的年份是否是闰年而不更改网页。
<html lang=\"en\">
<head>
<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" />
<meta name=\"keywords\" content=\"Web,programming\" />
<title>Leap year form</title>
</head>
<body>
<?php
$year = isset($_GET[\"leapyear\"]);
function is_leapyear($year){
if(is_numeric($year)){
if($year%4 ==0)
if($year%100 ==0)
if($year%400 ==0){
return true;
}
return false;
}
}
if (isset($_GET[\"confirm\"])){
if ($year == true){
echo\'<span style=\"color:#008631;\">\';
echo\"$year is a leap year</span>\";
}
else{
echo\'<span style=\"color:#FF0000;\">\';
echo \"$year is not a leap year</span>\";
}
}
?>
<h1>Lab 03 Task 2 - Leap Year</h1>
<form action = \"leapyear_selfcall.php\" method = \"get\" >
<label for=\"leapyear\">Enter a year</label>
<input type=\"text\" name=\"leapyear\"/>
<p><input type=\"submit\" name=\"confirm\" value=\"Check For Leap Year\"/></p>
</form>
</body>
</html>
我得到的结果是“1 是闰年”,而不是输入的输入。我在哪里犯了错误?
-
你好,记得缩进你的代码,这样更易理解,对你以后有很大的帮助!