调试需加入jquery文件
<script> <br>$(function(){ <br>$('#year').change(function(){ <br>if (ifLeapYear($(this).val())) <br>{ <br>if ($('#month').val() == 2 && $('#day').children().length == 29) <br>{ <br>$('#day').append('<option value="29">29</option>'); <br>} <br>} else <br>{ <br>if ($('#month').val() == 2 && $('#day').children().length == 30) <br>{ <br>$('#day :last-child').remove(); <br>} <br>} <br>}); <br><br>$('#month').change(function(){ <br>var thisValue = $(this).val(); <br>var dayValue = $('#day').val(); <br>var month1 = ['4','6','9','11']; <br>$('#day').html('<option value="">-请选择-</option>'); <br>var day = ''; <br>if (thisValue == '') <br>{ <br>return false; <br>} <br>if ($.inArray(thisValue, month1) != -1) <br>{ <br>day = setDay(30); <br>$('#day').append(day); <br>} else if ($(this).val() == '2') <br>{ <br>if ($('#year').val() != '' && ifLeapYear($('#year').val())) <br>{ <br>day = setDay(29); <br>} else <br>{ <br>day = setDay(28); <br>} <br>$('#day').append(day); <br>} else <br>{ <br>day = setDay(31); <br>$('#day').append(day); <br>} <br>$('#day').find('option[value=' dayValue ']').attr('selected',true); <br>}); <br>}) <br>function setDay(day) <br>{ <br>var dayInfo = ''; <br>for (var i=1; i<=day; i ) <BR>{ <BR>dayInfo = '<option value="' i '">' i '</option>'; <br>} <br>return dayInfo; <br>} <br>function ifLeapYear(year) <br>{ <br>if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) <br>{ <br>return true; <br>} else <br>{ <br>return false; <br>} <br>} <br></script> -请选择- 年 -请选择- 月 -请选择- 日
Statement: The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn