struts好像没有日期控件吧,自己写一个

解决方案 »

  1.   

    自己解决了。var mm_obj;
    var mm_curday;
    var mm_today;
    var mm_months = new Array("一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月");
    var mm_daysInMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
    /*var mm_days = new Array("Sunday", "Monday", "Tuesday",  "Wednesday", "Thursday", "Friday", "Saturday");*/
    var mm_days = new Array("日","一", "二", "三",  "四", "五", "六");var formName;
    //得到某月的天数
    function getDays(month, year) {
    if (1 == month)
    return ((0 == year % 4) && (0 != (year % 100))) ||
    (0 == year % 400) ? 29 : 28;
    else
    return mm_daysInMonth[month];
    }//得到今天的年,月,日
    function getToday() {
    this.now = new Date();
    this.year = this.now.getFullYear();
    this.month = this.now.getMonth();
    this.day = this.now.getDate();
    }mm_today = new getToday();
    mm_curday = new Date();function newCalendar() {
    mm_today = new getToday();
    var parseYear = parseInt(document.all.mm_year[document.all.mm_year.selectedIndex].text);
    var newCal = new Date(parseYear, document.all.mm_month.selectedIndex, 1);
    var day = -1;
    var startDay = newCal.getDay();
    var daily = 0;
    if ((mm_today.year == newCal.getFullYear()) &&(mm_today.month == newCal.getMonth()))
    day = mm_today.day;
    var tableCal = document.all.calendar.tBodies.dayList;
    var intDaysInMonth =getDays(newCal.getMonth(), newCal.getFullYear());
    for (var intWeek = 0; intWeek < tableCal.rows.length;intWeek++)
    for (var intDay = 0;intDay < tableCal.rows[intWeek].cells.length;intDay++)
    {
    var cell = tableCal.rows[intWeek].cells[intDay];
    if ((intDay == startDay) && (0 == daily))
    daily = 1;if(day==daily)
    //今天,调用今天的Class
    cell.className = "today";
    else if(intDay==6)
    //周六
    cell.className = "sunday";
    else if (intDay==0)
    //周日
    cell.className ="satday";
    else
    //平常
    cell.className="normal";if ((daily==mm_curday.getDate())&&(parseYear==mm_curday.getYear())&&(mm_curday.getMonth()==document.all.mm_month.selectedIndex)){
    cell.className="curday";}
    if ((daily > 0) && (daily <= intDaysInMonth))
    {
    cell.innerText = daily;
    daily++;
    }
    else
    cell.innerText = "";
    }
    }//这段代码处理鼠标点击的情况
    function getDate() {
    var sDate,_year,_month,_day;
    if ("TD" == event.srcElement.tagName)
        {
        if ("" != event.srcElement.innerText)
        {
        _year = document.all.mm_year.value;
        _month = document.all.mm_month.value;
        _month = (_month.length == 2) ? _month : ('0' + _month);
        _day = event.srcElement.innerText;
        _day = (_day.length == 2) ? _day : ('0' + _day);
        sDate = _year + "-" + _month + "-" + _day;
        mm_curday = new Date(document.all.mm_year.value,document.all.mm_month.selectedIndex,event.srcElement.innerText);
        m_obj.value=sDate ;
        showhidecalendar('hide','',formName);
        }
        }
    }
    //显示和隐藏日历
    function showhidecalendar(v,f,frmName){
        formName = frmName;
        m_obj=eval('document.'+frmName+'.elements(f)');
        newCalendar();
        var obj=document.all["Lcal"];
         if (obj.style) {
                obj=obj.style;
                v=(v=='show')?'visible':(v='hide')?'hidden':v;
        }
        //确定日历显示位置
        if((document.body.clientWidth - event.x) < 130)
            obj.left=document.body.clientWidth - 140 + ((document.body.scrollLeft=="undefined")?0:document.body.scrollLeft);
        else
            obj.left=event.x+ ((document.body.scrollLeft=="undefined")?0:document.body.scrollLeft);    if((document.body.clientHeight - event.y) < 130)
            obj.top=document.body.clientHeight - 140 + ((document.body.scrollTop=="undefined")?0:document.body.scrollTop);
        else
            obj.top=event.y + ((document.body.scrollTop=="undefined")?0:document.body.scrollTop);
        obj.visibility=v;
    }
    //<!---- start of calendar ------>
    function writeDIV(){
    document.write("<DIV id=Lcal style='height:130 width:130;POSITION: absolute ; TOP: 0px; left:150px ;VISIBILITY: hidden; Z-INDEX: 2'>");
    document.write("<TABLE border=0 bgcolor='#cccccc' cellspacing='0' cellpadding='1'><tr><td>");
    document.write("<TABLE border=0 bgcolor='#FFFFFF' cellspacing='0' cellpadding='2' width=100% height=100%>");
    document.write("<tr align=right bgcolor='#cccccc'><td width=120 height=10></td><td bgcolor='#cccccc' width=10 height=10 style='BACKGROUND-COLOR: lightsteelblue; BORDER-BOTTOM: #000000 1px solid; BORDER-LEFT: #FFFFFF 1px solid; BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #ffffff 1px solid; COLOR: #666699;' align='center'><a onclick=showhidecalendar('hide','',formName)  style='cursor:hand;font-size:7px'><font style='font-family:Webdings'>r</font></a></td></tr>");
    document.write("<TR><TD colspan=2>");
    document.write("<TABLE ID='calendar' cellspacing='0' cellpadding='0' border=0 width=128 style='color:#999900;font-size:12px;font-family:Arial;background:#FFFFFF'> ");
    document.write("<THEAD><TR><TD COLSPAN=7 ALIGN=CENTER>");
    document.write("<SELECT ID='mm_month' ONCHANGE='newCalendar()'>");
    document.write("<SCRIPT LANGUAGE='JavaScript'> for (var intLoop = 0; intLoop < mm_months.length; intLoop++) ");
    document.write("document.write(\"<OPTION VALUE= \" + (intLoop + 1) + \" \" + (mm_today.month == intLoop ? \"Selected\" : \"\") + \">\" +  mm_months[intLoop]);  ");
    document.write("</SCRIPT>");
    document.write("</SELECT>");document.write("<SELECT ID='mm_year' ONCHANGE='newCalendar()'>  ");
    document.write("<SCRIPT LANGUAGE='JavaScript'> for (var intLoop = mm_today.year-100; intLoop < (mm_today.year + 64); intLoop++) ");
    document.write("document.write(\"<OPTION VALUE= \" + intLoop + \" \" + (mm_today.year == intLoop ? \"Selected\" : \"\") + \">\" +  intLoop);  ");
    document.write("</SCRIPT>");
    document.write("</SELECT>");
    document.write("</TD></TR>");
    document.write("<TR height=1><TD colspan=7 bgcolor='#AABBCC'></TD></TR>");
    document.write("<TR CLASS='days'>");
    document.write("<SCRIPT LANGUAGE='JavaScript'>  ");
    document.write("document.write(\"<TD class=satday>\" + mm_days[0] + \"</TD>\");  ");
    document.write("for (var intLoop = 1; intLoop < mm_days.length-1; intLoop++) ");
    document.write("document.write(\"<TD>\" + mm_days[intLoop] + \"</TD>\");  ");
    document.write("document.write(\"<TD class=sunday>\" + mm_days[intLoop] + \"</TD>\");  ");
    document.write("</SCRIPT> </TR>");document.write("<TR height=1><TD colspan=7 bgcolor='#AABBCC'></TD></TR>");
    document.write("</THEAD>");
    document.write("<TBODY border=1 cellspacing=0 cellpadding=0 ID='dayList' ALIGN=CENTER ONCLICK='getDate()'>  ");
    document.write("<SCRIPT LANGUAGE='JavaScript'>  ")
    document.write("for (var intWeeks = 0; intWeeks < 6; intWeeks++) { ");
    document.write("document.write(\"<TR style='cursor:hand'>\");  ");
    document.write("for (var intDays = 0; intDays < mm_days.length; intDays++) ");
    document.write("document.write(\"<TD>&nbsp;</TD>\");  ");
    document.write("document.write(\"</TR>\");  ");
    document.write("} ");
    document.write("</SCRIPT></TBODY>  ");
    document.write("</TABLE></TD></TR>");
    document.write("</TABLE></TD></TR></table>");document.write("</div>");}
      

  2.   

    有javascript就可以实现了. 当你执行视图页后. 都转换成了普通的 form 标记了.