`
yuanpan365
  • 浏览: 6421 次
  • 性别: Icon_minigender_1
  • 来自: 湖北
社区版块
存档分类
最新评论

动态获取年月

阅读更多
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%
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>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>

<script type="text/javascript">
var date = new Date();
var d = date.getDate();
var year = date.getFullYear();
var month = date.getMonth()+1;
var importM = -5;
var startMonth = month+importM;
function years(){
if(month==1){
document.getElementById("year").options[0] = new Option(year-1,year-1);
}else{
if(startMonth>0){
document.getElementById("year").options[0] = new Option(year,year);
}else{
document.getElementById("year").options[0] = new Option(year,year);
document.getElementById("year").options[1] = new Option(year-1,year-1);
}
}
months();
}
function months(){
var x=0;
var y=0;
var years = document.getElementById("year").options[document.getElementById("year").selectedIndex].text;
if(years==year){
document.getElementById("month").innerText="";
var j=0;
if(startMonth>0){
j=startMonth;
}else{
j=1;
}
for(var i=j;i<month;i++){
document.getElementById("month").options[x] = new Option(i,i);
x++;
}
}
if(years==year-1){
document.getElementById("month").innerText="";
var a=12+startMonth;
for(var i=a;i<=12;i++){
document.getElementById("month").options[y] = new Option(i,i);
y++;
}
}
}
//function aa(){
//document.getElementById("selectid").innerHTML="<option value='ddd'>dddd</option>"
//}

function zhi(){
var y=document.getElementById("year").options[document.getElementById("year").selectedIndex].text;
var m=document.getElementById("month").options[document.getElementById("month").selectedIndex].text;
location.href="testServlet?aa="+y+"&bb="+m;
//location.href="testServlet?aa=bbb";
}
</script>

<body onload="years();">
<input type="button" value="点击" onclick="zhi();">
<input type="button" value="获得值" onclick="months();">

<form name="form1" action="testServlet" method="post">
<!-- <select id="year" onchange="months();"></select>-->
<!-- <select id="month"></select>-->
<br/>
<input type="text" name="username"><br/>
<input type="submit" value="Ok">
</form>
<html:form action="/test" method="post">
<html:select styleId="year" property="yearname" onchange="months();">
</html:select>
<html:select styleId="month" property="monthname">
</html:select>
<html:submit value="Ok"></html:submit>
</html:form>
</body>
</html>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics