[JavaScript] 纯文本查看 复制代码 <script type="text/javascript">
var date = new Date();
var datey = parseInt(date.getFullYear()); //取得当前的年份
var datem = parseInt(date.getMonth() + 1); //取得当前的月份
var dated = parseInt(date.getDate()); //取得当前的日期
var yyyy = document.getElementById("yyyy");
var mm = document.getElementById("mm");
var dd = document.getElementById("dd");
function init_obj(obj, start, end, seclect) {
for (i = start; i <= end; i++) {
obj.options.add(new Option(i, i));
for (j = 0; j < obj.options.length; j++) {
if (obj.options[j].value == seclect) {
obj.options[j].selected = "selected";
}
}
}
}
//判断闰年及大小月份确定日期下拉框中显示的日期数值
function change_dd() {
dd.options.length = 0;
var m = parseInt(mm.value);
var y = parseInt(yyyy.value);
var dayend;
if (m == 4 || m == 6 || m == 9 || m == 11) {
dayend = 30;
} else if (m == 2) {
dayend = 28;
if ((y % 4 == 0 && y % 100 != 0) || y % 400 == 0) {
dayend = 29;
}
} else {
dayend = 31;
}
init_obj(dd, 1, dayend);
}
init_obj(yyyy, datey - 5, datey + 5, datey); //年份下拉列表框,当前年份的前后5年
init_obj(mm, 1, 12, datem); //月份下列列表框
init_obj(dd, 1, 31, dated); //日期下列列表框
</script> |