我正在尝试在表单中自动选择月份、日期和年份。我确信这很简单,但我对 Javascript 很不熟悉。在下面的代码中,月份选择工作正常,但日期始终是实际日期的 +1,而年份根本不工作。如果有人可以提供帮助,将不胜感激!谢谢!
<form name="form" action="b.html" method="post">
<select id="month" name="month">
<option id="1" value="January">January</option>
<option id="2" value="February">February</option>
<option id="3" value="March">March</option>
<option id="4" value="April">April</option>
<option id="5" value="May">May</option>
<option id="6" value="June">June</option>
<option id="7" value="July">July</option>
<option id="8" value="August">August</option>
<option id="9" value="September">September</option>
<option id="10" value="October">October</option>
<option id="11" value="November">November</option>
<option id="12" value="December">December</option>
</select>
/
<select id="day" name="day">
<option id="1" value="1">1</option>
<option id="2" value="2">2</option>
<option id="3" value="3">3</option>
<option id="4" value="4">4</option>
<option id="5" value="5">5</option>
<option id="6" value="6">6</option>
<option id="7" value="7">7</option>
<option id="8" value="8">8</option>
<option id="9" value="9">9</option>
<option id="10" value="10">10</option>
<option id="11" value="11">11</option>
<option id="12" value="12">12</option>
<option id="13" value="13">13</option>
<option id="14" value="14">14</option>
<option id="15" value="15">15</option>
<option id="16" value="16">16</option>
<option id="17" value="17">17</option>
<option id="18" value="18">18</option>
<option id="19" value="19">19</option>
<option id="20" value="20">20</option>
<option id="21" value="21">21</option>
<option id="22" value="22">22</option>
<option id="23" value="23">23</option>
<option id="24" value="24">24</option>
<option id="25" value="25">25</option>
<option id="26" value="26">26</option>
<option id="27" value="27">27</option>
<option id="28" value="28">28</option>
<option id="29" value="29">29</option>
<option id="30" value="30">30</option>
<option id="31" value="31">31</option>
</select>
/
<select id="year" name="year">
<option id="2012" value="2012">2012</option>
<option id="2013" value="2013">2013</option>
<option id="2014" value="2014">2014</option>
<option id="2015" value="2015">2015</option>
<option id="2016" value="2016">2016</option>
<option id="2017" value="2013">2017</option>
<option id="2018" value="2014">2018</option>
<option id="2019" value="2015">2019</option>
<option id="2020" value="2016">2020</option>
</select>
<script>
var d = new Date();
var month = d.getMonth();
var day = d.getDate();
var year = d.getFullYear();
document.form.month[month].selected = month;
document.form.day[day].selected = day;
document.form.year[year].selected = year;
</script>
</form>