我有一个包含许多字段的表单。当用户选择他的出生日期时,我希望表单根据dob和今天自动计算年龄,并在年龄字段中报告该结果。
看看我再次实施的内容:全部,感谢您的回复。但我仍有实施问题。请参阅我的代码并更正:
<p> Date of Birth:
<input type="date" name="dob" value="" id="dob" placeholder="Date of Birth" required="required"/></p>
<script> function agefinding()
{
var birthDay = document.getElementById("dob").value;
var DOB = new Date(birthDay);
var today = new Date();
var age = today.getTime() - DOB.getTime();
age = Math.floor(age / (1000 * 60 * 60 * 24 * 365.25));
// alert(age);
//return age;
document.getElementById('age').value = age;
}</script>
<p> Age:
<input type="numeric" name="age" value="" id="age" placeholder="Age" required="required"/></p>