这是我的代码,用于输入他们的生日来计算一个人的年龄。我无法读取生日输入并在getAge函数中使用。此外,我无法在第二个文本框中显示年龄。我不确定如何纠正这些。HTML按钮没有运行JavaScript函数和函数输出不显示
<!DOCTYPE html>
<html lang="en">
<head>
<title>Age Calculator</title>
<script>
var birthday;
function getAge(birth) {
var bday = document.getElementById("bday");
var ageDisplay = document.getElementById("ageDisplay");
var today = new Date();
var curr_date = today.getDate();
var curr_month = today.getMonth() + 1;
var curr_year = today.getFullYear();
var pieces = birth.split('/');
var birth_date = pieces[0];
var birth_month = pieces[1];
var birth_year = pieces[2];
if (curr_month == birth_month && curr_date >= birth_date) return parseInt(curr_year - birth_year);
if (curr_month == birth_month && curr_date < birth_date) return parseInt(curr_year - birth_year - 1);
if (curr_month > birth_month) return parseInt(curr_year - birth_year);
if (curr_month < birth_month) return parseInt(curr_year - birth_year - 1);
}
var age = getAge(birthday);
ageDisplay.value = age
</script>
</head>
<body style="background-color:red">
<form>
<fieldset>
<label>Type your Date of Birth: </label>
<input type="text" id="bday" />
<input type="button" value="click me" onclick="getAge()" />
<br/>
<br/>
<label>Your Age is: </label>
<input type="text" id="ageDisplay" />
</fieldset>
</form>
<body>
</html>