发帖    主题    评论    推荐    标签    作者    订阅    查搜    注册   登陆   关注
 
面向对象 设计模式 领域驱动设计 企业架构 框架 开发教程 微服务 CQRS 扩展性 并发编程 事件溯源 分布式 SOA

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

2005-04-19 10:28
赞助商链接

我用的日期控件如下 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>
问题:如何把作成一表单提交呢??很菜鸟吧:(

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>

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();




2005-04-19 14:15

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

赞助商链接

赞助商链接

返回顶部

移动版 关于本站 使用帮助 联系管理员 最佳分辨率1366x768
OpenSource JIVEJDON Powered by JdonFramework Code © 2002-20 jdon.com