具体问题如下:
1、给每个具体日期加上链接(nomenu1.jsp?date=‘’);
2、给链接的页面传参数(该参数为具体日期nomenu1.jsp?date=‘’)
比如:
<%for(int r=0;r<6;r++){%>
<tr class="tab-xunhuan">
<%for(int d=0;d<7;d++){
%>
<td align="center" bgcolor="DCDCDC"><input name="dayBox" type="text" onclick="window.location='nomenu1.jsp?date=2';" size="4" style="background-color:#DCDCDC" maxlength="0" readonly></td>
<%}%>
</tr>
<%}%>
我的日期列表控件如下:
<%@ page contentType="text/html; charset=gb2312" language="java" %>
<html>
<head>
<title>日期选择器</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
body,td { font-size:9pt; }
input
{
color:333333;
font-size:16pt;
border-width:0;
padding:2;
width:25px;
background: fff9a0;
}
.mid{
margin:0 auto;
border:1px solid #00F;
}
.tab3{
width:1200px;
height:600px;
border-collapse:collapse;
text-align:center;
}
.tab3 td{
border:1px solid #999;
}
.tab-top th{
border:1px solid #999;
background-color:#82664F;
height:18px;
text-align:center;
}
.tab-xunhuan{
background-color:#FFF;
height:18px;
}
</style>
</head>
<script language=javascript>
<!--
var monthNames = new Array ( "", "1","2","3","4","5","6","7", "8", "9", "10", "11", "12" );
var endDay = new Array ( 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 );
var dayNow = 0;
var monthNow = 0;
var yearNow = 0;
function load ( form ) {
set_month_year_now ();
var found = false;
for ( var month=0; month<form.monthList.length; month++ )
if ( form.monthList[month].text == monthNames[monthNow] ) {
form.monthList[month].selected = true;
found = true;
}
if ( !found) {
error ();
return;
}
var found = false;
for ( var year=0; year<form.yearList.length; year++ )
if ( form.yearList[year].text == yearNow ) {
form.yearList[year].selected = true;
found = true;
}
if ( !found) {
error ();
return;
}
display_month ( form );
}
function preceding_month ( form ) {
var month_selected = form.monthList.selectedIndex;
var year_selected = form.yearList.selectedIndex;
if ( !month_selected && !year_selected ) {
error ();
return;
}
if ( month_selected > 0 )
month_selected --;
else {
month_selected = 11;
year_selected --;
}
form.monthList[month_selected].selected = true;
form.yearList[year_selected].selected = true;
display_month ( form );
}
function following_month ( form ) {
var month_selected = form.monthList.selectedIndex;
var year_selected = form.yearList.selectedIndex;
if ( month_selected >= ( form.monthList.length - 1 ) && year_selected >= ( form.yearList.length - 1 ) ) {
error ();
return;
}
if ( month_selected < 11 )
month_selected ++;
else {
month_selected = 0;
year_selected ++;
}
form.monthList[month_selected].selected = true;
form.yearList[year_selected].selected = true;
display_month ( form );
}
function set_month_year_now () {
var form = document.calendar;
var now = new Date ();
monthNow = now.getMonth () + 1;
yearNow = now.getYear ();
dayNow = now.getDate();
yearNow = ( yearNow < 100 ) ? yearNow + 1900 : yearNow;
var count = 0
for (var i = yearNow-1; i < yearNow + 2; i++) {
eval("form.yearList.options[count] = new Option('"+i+"', '"+i+"')");
count++;
}
form.yearList.selectedIndex = 103;
form.yearList.length = count;
}
function error () {
alert ( "超出范围!" );
}
function display_month ( form ) {
var month = form.monthList.selectedIndex + 1;
var year = parseInt ( form.yearList.options[ form.yearList.selectedIndex].text );
var start_day = start_day_in_month ( year, month );
var count = 0;
for ( var row=0; row<6; row++) {
for ( var col=0; col<7; col++ )
{
if ( row == 0 && col < ( start_day - 1 ) )
var day = "";
else if ( count < endDay[month] )
day = ++count;
else
day = "";
form.dayBox[(row*7)+col].style.display = "";
form.dayBox[(row*7)+col].style.color = "black";
if (day == "") {
form.dayBox[(row*7)+col].style.display = "none";
} else {
form.dayBox[(row*7)+col].value = day;
if (col%7 == 0) form.dayBox[(row*7)+col].style.color = "black";
if (yearNow == year && monthNow == month && dayNow == day) form.dayBox[(row*7)+col].style.color = "blue";;
}
}
}
}
function start_day_in_month ( year, month ) {
var day, daynum, ndays, mnum;
sday = start_day_in_year ( year );
endDay[2] = ( year % 4 ) ? 28 : 29;
if ( month == 1 )
daynum = sday;
else {
ndays = sday;
for ( mnum=2; mnum<month+1; mnum++ )
ndays = ndays + endDay[mnum-1];
daynum = ndays % 7;
}
daynum = (!daynum) ? 7 : daynum;
return (daynum);
}
function start_day_in_year ( year ) {
var y, m, d;
var n;
y = year - 1; m = 13; d = 1;
n = d + 2 * m + ( Math.floor ( ( 0.6 + (m + 1) ) ) + y );
n = n + Math.floor ( ((y / 4) - Math.floor ( (y / 100 ) ) + Math.floor ( ( y / 400 ) ) ) ) + 2 ;
n = Math.floor ( ( (n / 7 - Math.floor ( (n / 7) ) ) * 7 + 0.5 ) );
return (n+1);
}
function CheckDate(strDay) {
var docFrm = document.calendar;
var choice_daynum = 0;
var current_daynum = 0;
var day_temp;
if (strDay != "") {
var strY = docFrm.yearList.value;
var strM = docFrm.monthList.value;
var curr_y = new String(yearNow);
var curr_m = new String(monthNow);
var curr_d = new String(dayNow);
if (curr_m.length == 1) curr_m = "0"+curr_m;
if (curr_d.length == 1) curr_d = "0"+curr_d;
current_daynum = new Number(curr_y + curr_m + curr_d) ;
if (strM.length == 1) strM = "0"+strM;
if (strDay.length == 1) strDay = "0"+strDay;
choice_daynum = new Number(strY + strM + strDay);
parent.window.returnValue = strY+"-"+strM+"-"+strDay; //将选择的日期传递到父窗口中
//parent.window.close();
alert(returnValue);
}
return false;
}
-->
</script>
<body onLoad="load(document.calendar)" topmargin="0">
<div class="mid">
<form name="calendar">
<table class="tab1">
<tr>
<td colspan="3" height="10"></td>
</tr>
<tr>
<td width="205" nowrap="nowrap" align="left">年份
<select name="yearList" onChange="display_month(this.form)">
</select> 月份
<select name="monthList" size="1" onChange="display_month(this.form)">
<%for(int i=1;i<13;i++){%>
<option value="<%=i%>"><%=i%></option>
<%}%>
</select> </td>
</tr>
<tr>
<td colspan="3" height="6"></td>
</tr>
<tr>
<td colspan="3"><table class="tab2" >
<tr>
<td><table class="tab3" >
<tr class="tab-top">
<th nowrap="nowrap"><strong>日</strong></th>
<th nowrap="nowrap"><strong>一</strong></th>
<th nowrap="nowrap"><strong>二</strong></th>
<th nowrap="nowrap"><strong>三</strong></th>
<th nowrap="nowrap"><strong>四</strong></th>
<th nowrap="nowrap"><strong>五</strong></th>
<th nowrap="nowrap"><strong>六</strong></th>
</tr>
<%for(int r=0;r<6;r++){%>
<tr class="tab-xunhuan">
<%for(int d=0;d<7;d++){
%>
<td align="center" bgcolor="DCDCDC"><input name="dayBox" type="text" onclick="window.location='nomenu1.jsp?date=2';" size="4" style="background-color:#DCDCDC" maxlength="0" readonly></td>
<%}%>
</tr>
<%}%>
</table></td>
</tr>
</table></td>
</tr>
</table>
</form>
</div>
</body>
</html>
万分感谢。
------解决思路----------------------
有错别字 不好意思 重发一次
首先你肯定是要有年月的选择 这个你是可以获取到的
日期在你循环的时候给他们统一的name 然后给他们绑定事件 并且把当前的value传到函数里面 再在函数里面拼出个日期来就可以了
------解决思路----------------------
回复4楼:是的,但是怎么组合成yyyy-MM-dd,并传过去。劳烦给出具体代码,万分感谢。
function(date){var year = $("#year").val();var month = $("#month").val();window.local.href="nomenu1.jsp?date="+year+"-"+month+"-"+date}