用户要从 3 个下拉列表中选择一个日期。提交选择后,脚本将比较用户选择的日期并将其与用户的当前日期进行比较。如果用户选择的日期大于当前日期,则会出现错误提示。如果日期已经发生,那么它将显示在单独的窗口中。
我遇到的问题是两个日期之间的比较。我有一种感觉,问题在于为要比较的项目编写了不正确的路径。
我是初学者。任何帮助将不胜感激!
..................................................... …………………………………………………………………………………………………………………………………………
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Date of Birth</title>
<script language= "javascript" type="text/javascript">
function display() {
var d = new Date("mm/dd/yyyy");
var currentMonth = d.getMonth();
var currentDay = d.getDate();
var currentYear = d.getFullYear();
userMonth = Date.parse(document.getElementById("Month").value);
userDay = Date.parse(document.getElementById("Day").id);
userYear = Date.parse(document.getElementById("Year").value);
if(userYear >= currentYear){
if(userMonth === currentMonth){
if(userDay > currentDay){
alert("Sorry, this date has not occurred yet. Please submit a new entry. ");
}
else {
DispWin = window.open('', 'NewWin', 'toolbar=no,status=no,width=200,height=280')
message = "<ul><li><b>Month: </b>" + document.dob.Month.value + "</li>";
message += "<li><b>Day: </b>" + document.dob.Day.value + "</li>";
message += "<li><b>Year: </b>" + document.dob.Year.value + " </li></ul>";
DispWin.document.write(message);
}
}
else if(userMonth > currentMonth) {
alert("Sorry, this date has not occurred yet. Please submit a new entry. ");
}
else {
DispWin = window.open('', 'NewWin', 'toolbar=no,status=no,width=200,height=280')
message = "<ul><li><b>Month: </b>" + document.dob.Month.value + "</li>";
message += "<li><b>Day: </b>" + document.dob.Day.value + "</li>";
message += "<li><b>Year: </b>" + document.dob.Year.value + " </li></ul>";
DispWin.document.write(message);
}
}
else {
DispWin = window.open('', 'NewWin', 'toolbar=no,status=no,width=200,height=280')
message = "<ul><li><b>Month: </b>" + document.dob.Month.value + "</li>";
message += "<li><b>Day: </b>" + document.dob.Day.value + "</li>";
message += "<li><b>Year: </b>" + document.dob.Year.value + " </li></ul>";
DispWin.document.write(message);
}
}
</script>
</head>
<body>
<p> Please enter the date of birth of the applicant? <br />
<form action="" name="dob">
<select style="width: 100px" id="Month" name="Month">
<option>Month: </option>
<option id="0">January</option>
<option id="1">Febuary</option>
<option id="2">March</option>
<option id="3">April</option>
<option id="4">May</option>
<option id="5">June</option>
<option id="6">July</option>
<option id="7">August</option>
<option id="8">September</option>
<option id="9">October</option>
<option id="10">November</option>
<option id="11">December</option>
</select>
<select style="width: 80px" id="Day" name="Day">
<option>Day: </option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
<option>10</option>
<option>11</option>
<option>12</option>
<option>13</option>
<option>14</option>
<option>15</option>
<option>16</option>
<option>17</option>
<option>18</option>
<option>19</option>
<option>20</option>
<option>21</option>
<option>22</option>
<option>23</option>
<option>24</option>
<option>25</option>
<option>26</option>
<option>27</option>
<option>28</option>
<option>29</option>
<option>30</option>
<option>31</option>
</select>
<select style="width: 80px" id="Year" name="Year">
<option>Year: </option>
<option>Before 1980</option>
<option>1980</option>
<option>1981</option>
<option>1982</option>
<option>1983</option>
<option>1984</option>
<option>1985</option>
<option>1986</option>
<option>1987</option>
<option>1988</option>
<option>1989</option>
<option>1990</option>
<option>1991</option>
<option>1992</option>
<option>1993</option>
<option>1994</option>
<option>1995</option>
<option>1996</option>
<option>1997</option>
<option>1998</option>
<option>1999</option>
<option>2000</option>
<option>2001</option>
<option>2002</option>
<option>2003</option>
<option>2004</option>
<option>2005</option>
<option>2006</option>
<option>2007</option>
<option>2008</option>
<option>2009</option>
<option>2010</option>
<option>2011</option>
<option>2012</option>
<option>2013</option>
<option>2014</option>
</select>
<br /><br />
<input type="button" value="Submit" onclick="display();" />
</form>
</body>
</html>