<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="js/jquery-2.1.4.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
$(function() {
var year = $("#year");
var mouth = $("#mouth");
var day = $("#day")
var days = [0,31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
for (var i = 1945; i < 2025; i++) {
year.append("<option value=" + i + ">" + i + "</option>");
}
year.change(function(){
$("#mouth option[value!=0]").remove();
if ($("#year option:selected").val() != 0) {
for (var i = 1; i <= 12; i++) {
mouth.append("<option value=" + i + ">" + i + "</option>");
}
}
});
mouth.change(function(){
$("#day option[value!=0]").remove();
var tmp=$("#mouth option:selected").val();
if(checkLeapYear(year.val())){
days[2]=29;
}else{
days[2]=28;
}
for(var i = 1; i <= days[tmp]; i++){
day.append("<option value=" + i + ">" + i + "</option>");
}
});
});
function checkLeapYear(year){
if((year % 4 == 0 && year % 4 != 0) || year % 100 == 0){
return true;
}else{
return false;
}
}
</script>
</head>
<body>
<select id="year"><option value="0">年</option></select>年
<select id="mouth"><option value="0">月</option></select>月
<select id="day"><option value="0">日</option></select>日
</body>
</html>
Jquery时间联动
最新推荐文章于 2019-12-16 09:56:51 发布