Home > Web Front-end > JS Tutorial > body text

js date linkage example_javascript skills

WBOY
Release: 2016-05-16 16:50:11
Original
1264 people have browsed it

调试需加入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>



Related labels:
js
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template