求加减年的功能函数?
我先有一个拼好的select选择年份的下拉选项,代码如下:
<SCRIPT LANGUAGE= "JavaScript ">
<!--
var d=new Date()
document.write( " <select id=selyear> ");
var int;
int=new Array()
for(i=2003;i <2013;i++){
int[i]=i;
document.write( " <option "+((d.getYear()==i)? "selected ": " ")+ " value= " + int[i] + "> " + int[i] + " </option> ");
}
document.write( " </select> 年 ");
//-->
</SCRIPT>
现在想加这样一个函数:
<input type= "button " id= "SGY " name= "SGY " value= "上一年 " class= "button " onclick= "DateAdd(1); " />
<input type= "button " id= "XGY " name= "XGY " value= "下一年 " class= "button " onclick= "DateAdd(-1); " />
能够加减select里面的年度值
------解决方案-------------------- <SCRIPT LANGUAGE= "JavaScript ">
<!--
var d=new Date()
document.write( " <select id=selyear> ");
var int;
int=new Array()
for(i=2003;i <2013;i++){
int[i]=i;
document.write( " <option "+((d.getYear()==i)? "selected ": " ")+ " value= " + int[i] + "> " + int[i] + " </option> ");
}
document.write( " </select> 年 ");
function DateAdd(n){
var dlt = document.getElementById( "selyear ");
var len = dlt.options.length;
var idx = dlt.selectedIndex - n ;
dlt.selectedIndex = idx < 0? 0 : (idx > len-1 ? len-1 : idx);
}
//-->
</SCRIPT>
<input type= "button " id= "SGY " name= "SGY " value= "上一年 " class= "button " onclick= "DateAdd(1); " />
<input type= "button " id= "XGY " name= "XGY " value= "下一年 " class= "button " onclick= "DateAdd(-1); " />