<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>TimeSelect</title>
<script type="text/javascript" src="js/jquery-1.8.2.js"></script>
<script type="text/javascript">
var nowDate = new Date();
var timestamp = nowDate.getFullYear() + '年' + (nowDate.getMonth()+1) + '月';
$(function(){
for(var i = 0; i<12; i++){
$('#showTime').append('<option>'+ timestamp +'</option>');
var month = nowDate.getMonth();
var year = nowDate.getFullYear();
if( month -1 < 0){
month = 12 ;
year = year - 1;
}else{
month = month;
}
nowDate.setFullYear(year,month,null);
timestamp = nowDate.getFullYear() + '年' + (nowDate.getMonth()+1) + '月';
}
});
</script>
</head>
<body>
<select id="showTime">
</select>
</body>
</html>
获取从当年当月起往前推12个月的某年某月的下拉框(JS+JQUERY)
最新推荐文章于 2024-09-11 13:58:36 发布