如何使用日期控件(又菜了:()

ronghao100 05-04-19

我用的日期控件如下 DateInput.js
function DateInput(name,yearBegin,yearEnd)

{

this.name=name;

this.yearBegin=yearBegin;

this.yearEnd=yearEnd;



this.outputHTML=DateInput_outputHTML;

this.onMonthChanged=DateInput_onMonthChanged;

this.onYearChanged=DateInput_onYearChanged;

}

function DateInput_onYearChanged()

{

var yearSelector=document.all[this.name+"_year"];

var monthSelector=document.all[this.name+"_month"];

var daySelector=document.all[this.name+"_day"];



var currentYear=parseInt(yearSelector.value);

var currentMonth=parseInt(monthSelector.value);



if(currentMonth!=2) return;



var days=30;

var isLeapYear=false;

if(currentYear % 400 == 0 || (currentYear % 4 == 0 && currentYear % 100 !=0)) days=29;

else days=28;



var html="";

daySelector.length=0;

for(i=1;i<=days;i++) daySelector.options[daySelector.length] = new Option(i,i)

}

function DateInput_onMonthChanged()

{

var yearSelector=document.all[this.name+"_year"];

var monthSelector=document.all[this.name+"_month"];

var daySelector=document.all[this.name+"_day"];



var currentYear=parseInt(yearSelector.value);

var currentMonth=parseInt(monthSelector.value);



var days=30;

var isLeapYear=false;

if(currentYear%400==0||(currentYear%4==0 && currentYear % 100!=0)) isLeapYear=true;

switch(currentMonth)

{

case 1: case 3: case 5: case 7: case 8: case 10: case 12: days=31;

}

if(currentMonth==2)

if(isLeapYear) days=29;

else days=28;



var html="";

daySelector.length=0;

for(i=1;i<=days;i++) daySelector.options[daySelector.length] = new Option(i,i)

}

function DateInput_outputHTML()

{

var html="";

var i;



html+="<select name='"+this.name+"_year' onchange='"+this.name+".onYearChanged()'>";

for(i=this.yearBegin;i<=this.yearEnd;i++)

html+=" <option value='"+i+"'>"+i+"</option>";

html+="</select>";



html+="<select name='"+this.name+"_month' onchange='"+this.name+".onMonthChanged()'>";

for(i=1;i<=12;i++)

html+=" <option value='"+i+"'>"+i+"</option>";

html+="</select>";



html+="<select name='"+this.name+"_day'>";

for(i=1;i<=31;i++)

html+=" <option value='"+i+"'>"+i+"</option>";

html+="</select>";

document.write(html);

}
date.jsp
<html>

<head><script src="DateInput.js"></script></head>

<body>
<script language="javascript">

var date1=new DateInput("date1",2001,2005);
var date2=new DateInput("date2",2001,2005);

date1.outputHTML();

date2.outputHTML();

</script>

</form>


</body>

</html>
问题:如何把作成一表单提交呢??很菜鸟吧:(

ronghao100
2005-04-19 10:30

date.jsp




<html>

<head><script src="DateInput.js"></script></head>

<body>
<script language=
"javascript">

var date1=new DateInput(
"date1",2001,2005);
var date2=new DateInput(
"date2",2001,2005);

date1.outputHTML();

date2.outputHTML();

</script>
</form>


</body>

</html>

ronghao100
2005-04-19 10:39

date.jsp



var date1=new DateInput("date1",2001,2005);
var date2=new DateInput("date2",2001,2005);

date1.outputHTML();

date2.outputHTML();




ronghao100
2005-04-19 14:15

已经搞定!但被头K了一顿:)