生日代码需要ajax

时间:2014-04-18 11:14:19

标签: php jquery ajax date

我有下一个代码,我需要做"选择"现在这一天。

例如:今天是2014年4月18日所以:

day=18
month=04
year=14

如果不明白:

<select name="day" id="day">
<option value="na">day</option>
<option value="01">1</option>
<option value="02">2</option>
<option value="03">3</option>
<option value="04">4</option>
<option value="05">5</option>
<option value="06">6</option>
<option value="07">7</option>
<option value="08" selected>8</option>
<option value="09">9</option>
<option value="10">10</option>
<option value="11">11</option>
</select>

和月和年....

完整代码:

<select name="day" id="day">
<option value="na">day</option>
<option value="01">1</option>
<option value="02">2</option>
<option value="03">3</option>
<option value="04">4</option>
<option value="05">5</option>
<option value="06">6</option>
<option value="07">7</option>
<option value="08">8</option>
<option value="09">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>/
<select name="month" id="month">
<option value="na">month</option>
<option value="01">January</option>
<option value="02">February</option>
<option value="03">March</option>
<option value="04">April</option>
<option value="05">May</option>
<option value="06">June</option>
<option value="07">July</option>
<option value="08">August</option>
<option value="09">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>/
<select name="year" id="year">
<option value="na">year</option>
<option value="14">2014</option>
</select>

简单但我需要帮助...

如果可以,我宁愿更多地使用。

1 个答案:

答案 0 :(得分:0)

AJAX与此有什么关系?

document.getElementById('day').selectedIndex = day;
document.getElementById('month').selectedIndex = month;
document.getElementById('year').selectedIndex = year-2013;
// "year-2013" will need adjusting if you have more than just the current year
// if they are in increasing order, replace 2013 with "lowest year -1"
// otherwise, do "highest year +1" - year