function drawCal(firstDay,lastDate,date,monthName,year)
{
//constant table settings
var headerHeight=50 //height of the table's beader cell
var border=2 //3D height of table'border
var cellspacing=4 //widthof table's border
var headerColor="midnightblue" //colorof table's header
var headerSize="+3" //size of tables header font
var colWidth=60 //widthof columns in table
var dayCellHeight=25 //heigth of cells containing days of the week
var dayColor="darkblue" //color of font representing week days
var cellHeight=40 //height of cells representing dates in the calendar
var timeColor="purple" //color of font representing current time 
var todayColor="red"  
//create basic table structure
// var text="" //initialize accumulative variable to empty string 
// text+='<input type=text name=timeselect id=timeselect size=50 style="position:relative;top:-3px;left:375px;" >'
// text+='<input type=button id=btnselect size=2 style="position:relative;top:-3px;left:375px;">'
text+='<CENTER>'
text+='<TABLE BORDER='+border+' CELLSPACING='+cellspacing+'>' //table settings
//text+='<tr  height=20px><td colspan=7><input type=text name=timeselect id=timeselect size=50></td></tr>'
text+='<Tr HEIGHT='+headerHeight+'>' //create table header cell
text+='<td colspan=2 height=100% align=lift onclick="preMonth()" style="cursor:pointer">上月</td>'
text+='<td colspan=3 height=100%> <FONT COLOR="'+headerColor+'" SIZE='+headerSize+'>' //set font for table header
text+=monthName+''+year
text+='</FONT></td>' //close table header's font setting
text+='<td colspan=2 height=100% align=right><a href='+nextMonth()+'>下月</a></td>'
text+='</Tr>' //close header cell

//variables to hold constant settings
var openCol='<TD WIDTH='+colWidth+'HEIGHT='+dayCellHeight+'>'
openCol+='<FONT COLOR="'+dayColor+'">'
var closeCol='</FONT></TD>'

//create array of abbreviated day names
//得到星期几的名称
var weekDay=new Array(8)

weekDay[0]="星期天";
weekDay[1]="星期一";
weekDay[2]="星期二";
weekDay[3]="星期三";
weekDay[4]="星期四";
weekDay[5]="星期五";
weekDay[6]="星期六";

//create first row of table to set column width and specitfy week day 
text+='<TR ALIGN="center" VALIGN="center">'

for(var dayNum=0;dayNum<7;++dayNum)
{

text+=openCol+weekDay[dayNum]+closeCol

}

text+='</TR>'

//declaration and initialization of two variables to help with tables
var digit =1
var curCell=1

//将日期摆放在日历上
var rownum=Math.ceil((lastDate+firstDay-1)/7);
for(var row=1;row<=rownum;++row)
{

text+='<TR ALIGN="right" VALIGN="top">'

for(var col=1;col<=7;++col)
{
if(digit>lastDate)
{
break
}
if(curCell<firstDay)
{
text+='<TD></TD>'
curCell++
}
else
{
if(digit==date) //current cell represent today's date
{
text+='<TD HEIGHT="'+cellHeight+'" onclick=showTime('+digit+') style="cursor:pointer">'
text+='<FONT COLOR="'+todayColor+'">'
text+=digit
text+='</FONT><BR>'
text+='<FONT COLOR="'+timeColor+'"SIZE=2>'
text+='<CENTER>'+getTime()+'</CENTER>'
text+='</FONT>'
text+='</TD>'

}
else{
text+='<TD HEIGHT='+cellHeight+' onclick=showTime('+digit+') style="cursor:pointer">'+digit+'</TD>'
}
digit++
}

}

text+='</TR>'
}
//close all basic table tags
text+='</TABLE>'
text+='</CENTER>'
document.all.tempDiv.innerHTML = text


}

解决方案 »

  1.   

    function preMonth(){
    var curr_month = getselectedMonth();
    var curr_year = getselectedYear();
    if(curr_month <= 0){
    curr_month = 11;
    curr_year--;
    }
    else  curr_month--; var url = setUrlParam(document.location.href,'year',curr_year);
    url = setUrlParam(url,'month',curr_month);
    return url;

    }
      

  2.   

    应该不是没有调用到的问题吧.
    楼主在preMonth里加上alert()试试
      

  3.   

    调用到了的,我试过了,如果text+='<td colspan=2 height=100% align=right><a href='+preMonth()+'>上月</a></td>' 这样就没有问题的,但是有一个不好的地方就是要刷新一下,所以想用onclick试试,但是preMonth返回的是超链接,所以onclick不行了,有什么其它方法吗
      

  4.   

    那肯定是别的地方出问题了.
    href="javascript:xxx()"
    这样的写法本身肯定是没问题的.
      

  5.   

    href="javascript:xxx()" 这样写是对的,编译能通过,但是不能调用,我用alert() 试了
      

  6.   

    function preMonth(){
    var curr_month = getselectedMonth();
    var curr_year = getselectedYear();
    if(curr_month <= 0){
    curr_month = 11;
    curr_year--;
    }
    else  curr_month--; var url = setUrlParam(document.location.href,'year',curr_year);
    url = setUrlParam(url,'month',curr_month);
    return url;
    /*var now=new Date()

    var monthName=getMonthName(curr_month)
    var date=now.getDate()

    now = null
    var firstDayInstance=new Date(curr_year,curr_month,1)
    var firstDay=firstDayInstance.getDay()
    firstDayInstance=null
    window.alert("premonth")
    window.alert(curr_month)
    var days=getDays(curr_month,curr_year)
    drawCal(firstDay+1,days,date,monthName,(curr_year<100)?1900+curr_year:curr_year)
    */
    }function getselectedMonth(){
    var url = document.location.href;
    var month = getUrlParam(url,"month");
    if( month == ""){
    var now = new Date();
    month = now.getMonth();
    }
    window.alert("getselectedMonth")
    window.alert(month)
    return month;
    }function getselectedYear(){
    var url = document.location.href;
    var year = getUrlParam(url,"year");
    if( year == ""){
    var now = new Date();
    year = now.getYear();
    }
    window.alert("year")
    return year;
    }function getUrlParam(url, param)
    {
      var re = new RegExp("(\\\?|&)" + param + "=([^&]+)(&|$)", "i");
    var m = url.match(re);
      if (m)
       return m[2];
      else
      return '';
    }
    function setUrlParam(url, param, v)
    {
      var re = new RegExp("(\\\?|&)" + param + "=([^&]+)(&|$)", "i");
    var m = url.match(re);
      if (m)
      {
       return (url.replace(re, function($0, $1, $2) { return ($0.replace($2, v)); } ));
      }
      else
      {
       if (url.indexOf('?') == -1)
        return (url + '?' + param + '=' + v);
       else
       return (url + '&' + param + '=' + v);
    }
    }
      

  7.   

    你是用什么方法试的啊 onclick调用吗?还是用a herf调用啊