查询后如何保持下拉框中年月日的值(年,月的值可保存,日期搞不定)
如标题,这是做的一个动态下拉联动,日期的值根据月份的不同作相应变化,现在问题是点击查询后下拉框中无法保存所选择日期的值,请问各位大虾如何解决?
附主要代码:
这是脚本:
<script language="javascript1.2">
function changeDay(yObj, mObj, dObj) {
var arr28 = [["00","--- Select Date ---"],["01","01"],["02","02"],["03","03"],["04","04"],["05","05"],["06","06"],["07","07"],["08","08"],["09","09"],["10","10"],["11","11"],["12","12"],["13","13"],["14","14"],["15","15"],["16","16"],["17","17"],["18","18"],["19","19"],["20","20"],["21","21"],["22","22"],["23","23"],["24","24"],["25","25"],["26","26"],["27","27"],["28","28"]];
var arr29 = [["00","--- Select Date ---"],["01","01"],["02","02"],["03","03"],["04","04"],["05","05"],["06","06"],["07","07"],["08","08"],["09","09"],["10","10"],["11","11"],["12","12"],["13","13"],["14","14"],["15","15"],["16","16"],["17","17"],["18","18"],["19","19"],["20","20"],["21","21"],["22","22"],["23","23"],["24","24"],["25","25"],["26","26"],["27","27"],["28","28"],["29","29"]];
var arr30 = [["00","--- Select Date ---"],["01","01"],["02","02"],["03","03"],["04","04"],["05","05"],["06","06"],["07","07"],["08","08"],["09","09"],["10","10"],["11","11"],["12","12"],["13","13"],["14","14"],["15","15"],["16","16"],["17","17"],["18","18"],["19","19"],["20","20"],["21","21"],["22","22"],["23","23"],["24","24"],["25","25"],["26","26"],["27","27"],["28","28"],["29","29"],["30","30"]];
var arr31 = [["00","--- Select Date ---"],["01","01"],["02","02"],["03","03"],["04","04"],["05","05"],["06","06"],["07","07"],["08","08"],["09","09"],["10","10"],["11","11"],["12","12"],["13","13"],["14","14"],["15","15"],["16","16"],["17","17"],["18","18"],["19","19"],["20","20"],["21","21"],["22","22"],["23","23"],["24","24"],["25","25"],["26","26"],["27","27"],["28","28"],["29","29"],["30","30"],["31","31"]];
var arrstar = [["00","--- Select Date ---"]];
var d = new Date();
var star = "*";
var year = yObj[yObj.selectedIndex].value;
var month = mObj[mObj.selectedIndex].value;
if (month == 00) {
resetSelectOptionValue(dObj, arrstar, 0);
} else {
month = parseInt(mObj[mObj.selectedIndex].value, 10) - 1;
d.setFullYear(year, month, 31);
if (d.getMonth() == month) {
resetSelectOptionValue(dObj, arr31, 0);
} else {
d.setFullYear(year, month, 30);
if (d.getMonth() == month) {
resetSelectOptionValue(dObj, arr30, 0);
} else {
d.setFullYear(year, month, 29);
if (d.getMonth() == month) {
resetSelectOptionValue(dObj, arr29, 0);
} else {
d.setFullYear(year, month, 28);
if (d.getMonth() == month) {
resetSelectOptionValue(dObj, arr28, 0);
} else {
if (d.getMonth() == 8) {
resetSelectOptionValue(dObj, arr31, 0);
} else {
if (d.getMonth() == 9) {
resetSelectOptionValue(dObj, arr30, 0);
}
}
}
}
}
}
}
}
function resetSelectOptionValue(select, valueAndText, selectedIndex) {
var leng = select.options.length;
for (i = 0; i < valueAndText.length; i++) {
var option = new Option();
option.value = valueAndText[i][0];
option.text = valueAndText[i][1];
try {
select.add(option, select.options[i]);
} catch (e) {
select.add(option, i);
}
}
for (i = 0; i < leng; i++) {
select.remove(select.options.length - 1);
}
select.selectedIndex = selectedIndex;
}
</select>
下面是jsp代码:
<td bgcolor="#FFFFFF" width="60%" align="left">
<select name="fy" class="bbsselect" onChange="javascript:changeDay(report.fy, report.fm, report.fd);">
<%for(int i = 2004; i < 2015 ; i++ ){%>
<option value="<%=i%>"<%if(mdr.fy.equals(""+i+"")){%> selected <%}%>><%=i%></option>
<%}%>
</select>
<select name="fm" class="bbsselect" onChange="javascript:changeDay(report.fy, report.fm, report.fd);">
<option value="00" <%if(mdr.fm.equals("00")){%> selected <%}%>>--- Select Month ---</option>
<option value="01" <%if(mdr.fm.equals("01")){%> selected <%}%>><%=lang.getProperty("report_month_01")%></option>
<option value="02" <%if(mdr.fm.equals("02")){%> selected <%}%>><%=lang.getProperty("report_month_02")%></option>
<option value="03" <%if(mdr.fm.equals("03")){%> selected <%}%>><%=lang.getProperty("report_month_03")%></option>
<option value="04" <%if(mdr.fm.equals("04")){%> selected <%}%>><%=lang.getProperty("report_month_04")%></option>
<option value="05" <%if(mdr.fm.equals("05")){%> selected <%}%>><%=lang.getProperty("report_month_05")%></option>
<option value="06" <%if(mdr.fm.equals("06")){%> selected <%}%>><%=lang.getProperty("report_month_06")%></option>
<option value="07" <%if(mdr.fm.equals("07")){%> selected <%}%>><%=lang.getProperty("report_month_07")%></option>
<option value="08" <%if(mdr.fm.equals("08")){%> selected <%}%>><%=lang.getProperty("report_month_08")%></option>
<option value="09" <%if(mdr.fm.equals("09")){%> selected <%}%>><%=lang.getProperty("report_month_09")%></option>
<option value="10" <%if(mdr.fm.equals("10")){%> selected <%}%>><%=lang.getProperty("report_month_10")%></option>
<option value="11" <%if(mdr.fm.equals("11")){%> selected <%}%>><%=lang.getProperty("report_month_11")%></option>
<option value="12" <%if(mdr.fm.equals("12")){%> selected <%}%>><%=lang.getProperty("report_month_12")%></option>
</select>
<select name="fd" class="bbsselect">
<%-- cs070205cddv --%>
<option value="00" selected>--- Select Date ---</option>
<%-- ------------ --%>
</select>
</td>
[解决办法]
怎么会搞不定呢,日期和月数不都一样吗?
[解决办法]
按你的实现方式,都是个循环而已,只不过月的循环次数是常量,日期的循环次数是个变量而已。有难度么?