你原来的方法我没改,只是多添加了一个方法
<style type="text/css">
.body, td{
font-family:"Arial";
font-size:8pt;
color:#000000;
}
.TrOut{
border-left:1px solid #f4f4f4; border-right:1px solid #999999; border-top:1px solid #f4f4f4; border-bottom:1px solid #999999; background:#dddddd; height:26;}
.TdOver{
border-left:1px solid #9c9c9c; border-right:1px solid #ffffff; border-top:1px solid #9c9c9c; border-bottom:1px solid #ffffff; background:#eeeeee; height:20;}
.TdOut{
border-left:1px solid #ffffff; border-right:1px solid #9c9c9c; border-top:1px solid #ffffff; border-bottom:1px solid #9c9c9c; background:#eeeeee; height:20;}
</style>
<script language="JScript">
function TableFunction(){
        this.GetDateStr=function(y,m){
                this.DayArray=[];
                for(var i=0;i<42;i++)this.DayArray[i]=" ";
                for(var i=0;i<new Date(y,m,0).getDate();i++)this.DayArray[i+new Date(y,m-1,1).getDay()]=i+1;
                return this.DayArray;
                }
        this.GetTableStr=function(y,m){
                this.DateArray=["日","一","二","三","四","五","六"];
                this.DStr="<table oncontextmenu='return false' onselectstart='return false' style='width:160;cursor:default;border:1 solid #9c9c9c;border-right:0;border-bottom:0;filter:progid:dximagetransform.microsoft.dropshadow(color=#e3e3e3,offx=3,offy=3,positive=true)' border='0' cellpadding='0' cellspacing='0'>\n"+
                "<tr><td colspan='7' class='TrOut'>"+
                "<table width='100%' height='100%'border='0' cellpadding='0' cellspacing='0'><tr align='center'>\n"+
                "<td width='20' style='font-family:\"webdings\";font-size:9pt' onclick='TableFunction().JumpToRun(\"b\")' onmouseover='this.style.color=\"#ff9900\"' onmouseout='this.style.color=\"\"'>3</td>\n"+
                "<td id='YearTD' width='70' onmouseover='this.style.background=\"#cccccc\"' onmouseout='this.style.background=\"\"' onclick='TableFunction().WriteSelect(this,this.innerText.split(\" \")[0],\"y\",false)'>"+y+" 年</td>\n"+
                "<td id='MonthTD' width='47' onmouseover='this.style.background=\"#cccccc\"' onmouseout='this.style.background=\"\"' onclick='TableFunction().WriteSelect(this,this.innerText.split(\" \")[0],\"m\",false)'>"+m+" 月</td>\n"+
                "<td width='20' style='font-family:\"webdings\";font-size:9pt' onclick='TableFunction().JumpToRun(\"n\")' onmouseover='this.style.color=\"#ff9900\"' onmouseout='this.style.color=\"\"'>4</td></tr></table>\n"+
                "</td></tr>\n"+
                "<tr align='center'>\n";
                for(var i=0;i<7;i++)
                this.DStr+="<td class='TrOut'>"+DateArray[i]+"</td>\n";
                this.DStr+="</tr>\n";
                for(var i=0;i<6;i++){
                this.DStr+="<tr align='center'>\n";
                for(var j=0;j<7;j++){
                        var CS=new Date().getDate()==this.GetDateStr(y,m)[i*7+j]?"TdOver":"TdOut";
                        this.DStr+="<td id='TD' class='"+CS+"' cs='"+CS+"' onmouseover='this.className=\"TdOver\"' onmouseout='if(this.cs!=\"TdOver\")this.className=\"TdOut\"'  onmousedown='TableFunction().createPop()' onclick='TableFunction().AlertDay()'>"+this.GetDateStr(y,m)[i*7+j]+"</td>\n";
                        }
                this.DStr+="</tr>\n";
                }
                this.DStr+="</tabe>";
                return this.DStr;
                }
        this.WriteSelect=function(obj,values,action,getobj){
                if(values=="")return;
                if(getobj){
                        obj.innerHTML=values+(action=="y"?" 年":" 月");
                        this.RewriteTableStr(YearTD.innerText.split(" ")[0],MonthTD.innerText.split(" ")[0]);
                        return false;
                        }
                var StrArray=[];
                if(action=="y"){
                        for(var i=0;i<15;i++){
                                var year=values-7+i;
                                StrArray[i]="<option value='"+year+"' "+(values==year?"selected":"")+"> "+year+"年</option>\n";
                                }
                        obj.innerHTML="<select id='select1' style='width:67' onchange='TableFunction().WriteSelect(parentElement,this.value,\"y\",true)' onblur='YearTD.innerText=this.value+\" 年\"'>\n"+StrArray.join("")+"</select>";
                        select1.focus();
                        }
                if(action=="m"){
                        for(var i=1;i<13;i++)
                                StrArray[i]="<option value='"+i+"' "+(i==values?"selected":"")+"> "+i+"月</option>\n";
                        obj.innerHTML="<select id='select2' style='width:47' onchange='TableFunction().WriteSelect(parentElement,this.value,\"m\",true)' onblur='MonthTD.innerText=this.value+\" 月\"'>\n"+StrArray.join("")+"</select>";
                        select2.focus();
                        }
                }
        this.RewriteTableStr=function(y,m){
                var TArray=this.GetDateStr(y,m);
                var len=TArray.length;
                for(var i=0;i<len;i++){
                        TD[i].innerHTML=TArray[i];
                        TD[i].className="TdOut";
                        TD[i].cs="TdOut";
                        if(new Date().getYear()==y&&new Date().getMonth()+1==m&&new Date().getDate()==TArray[i]){
                                TD[i].className="TdOver";
                                TD[i].cs="TdOver";
                                }
                        }
                }
        this.JumpToRun=function(action){
                var YearNO=YearTD.innerText.split(' ')[0];
                var MonthNO=MonthTD.innerText.split(' ')[0];
                if(action=="b"){
                        if(MonthNO=="1"){
                                MonthNO=13;
                                YearNO=YearNO-1;
                                }
                        MonthTD.innerText=MonthNO-1+" 月";
                        YearTD.innerText=YearNO+" 年";
                        this.RewriteTableStr(YearNO,MonthNO-1);
                        }
                if(action=="n"){
                        if(MonthNO=="12"){
                                MonthNO=0;
                                YearNO=YearNO-(-1);
                                }
                        YearTD.innerText=YearNO+" 年";
                        MonthTD.innerText=MonthNO-(-1)+" 月";
                        this.RewriteTableStr(YearNO,MonthNO-(-1));
                        }
                }
        this.AlertDay=function(){
                 if(event.srcElement.innerText!=" ")
                 alert(YearTD.innerText.split(' ')[0]+"年"+MonthTD.innerText.split(' ')[0]+"月"+event.srcElement.innerText+"日");
                 }
        this.createPop=function()
        {
         if(event.button==2)
         {
                 var oPopup = window.createPopup();
var oPopupBody = oPopup.document.body;
oPopupBody.innerHTML = "<div style='cursor:hand;background:buttonface;overflow:hidden;margin:0px;border:2px outset;' onclick='alert(this.innerHTML)'>"+YearTD.innerText.split(' ')[0]+"年"+MonthTD.innerText.split(' ')[0]+"月"+event.srcElement.innerText+"日"+"</div>";
oPopup.show(100, 100, 200, 25, document.body);
         }
        }
        return this;
        }
        
document.write(TableFunction().GetTableStr(new Date().getYear(),new Date().getMonth()+1));
</script>

解决方案 »

  1.   

    和你的需求有些出入,再改下
    <style type="text/css">
    .body, td{
    font-family:"Arial";
    font-size:8pt;
    color:#000000;
    }
    .TrOut{
    border-left:1px solid #f4f4f4; border-right:1px solid #999999; border-top:1px solid #f4f4f4; border-bottom:1px solid #999999; background:#dddddd; height:26;}
    .TdOver{
    border-left:1px solid #9c9c9c; border-right:1px solid #ffffff; border-top:1px solid #9c9c9c; border-bottom:1px solid #ffffff; background:#eeeeee; height:20;}
    .TdOut{
    border-left:1px solid #ffffff; border-right:1px solid #9c9c9c; border-top:1px solid #ffffff; border-bottom:1px solid #9c9c9c; background:#eeeeee; height:20;}
    </style>
    <script language="JScript">
    function TableFunction(){
            this.GetDateStr=function(y,m){
                    this.DayArray=[];
                    for(var i=0;i<42;i++)this.DayArray[i]=" ";
                    for(var i=0;i<new Date(y,m,0).getDate();i++)this.DayArray[i+new Date(y,m-1,1).getDay()]=i+1;
                    return this.DayArray;
                    }
            this.GetTableStr=function(y,m){
                    this.DateArray=["日","一","二","三","四","五","六"];
                    this.DStr="<table oncontextmenu='return false' onselectstart='return false' style='width:160;cursor:default;border:1 solid #9c9c9c;border-right:0;border-bottom:0;filter:progid:dximagetransform.microsoft.dropshadow(color=#e3e3e3,offx=3,offy=3,positive=true)' border='0' cellpadding='0' cellspacing='0'>\n"+
                    "<tr><td colspan='7' class='TrOut'>"+
                    "<table width='100%' height='100%'border='0' cellpadding='0' cellspacing='0'><tr align='center'>\n"+
                    "<td width='20' style='font-family:\"webdings\";font-size:9pt' onclick='TableFunction().JumpToRun(\"b\")' onmouseover='this.style.color=\"#ff9900\"' onmouseout='this.style.color=\"\"'>3</td>\n"+
                    "<td id='YearTD' width='70' onmouseover='this.style.background=\"#cccccc\"' onmouseout='this.style.background=\"\"' onclick='TableFunction().WriteSelect(this,this.innerText.split(\" \")[0],\"y\",false)'>"+y+" 年</td>\n"+
                    "<td id='MonthTD' width='47' onmouseover='this.style.background=\"#cccccc\"' onmouseout='this.style.background=\"\"' onclick='TableFunction().WriteSelect(this,this.innerText.split(\" \")[0],\"m\",false)'>"+m+" 月</td>\n"+
                    "<td width='20' style='font-family:\"webdings\";font-size:9pt' onclick='TableFunction().JumpToRun(\"n\")' onmouseover='this.style.color=\"#ff9900\"' onmouseout='this.style.color=\"\"'>4</td></tr></table>\n"+
                    "</td></tr>\n"+
                    "<tr align='center'>\n";
                    for(var i=0;i<7;i++)
                    this.DStr+="<td class='TrOut'>"+DateArray[i]+"</td>\n";
                    this.DStr+="</tr>\n";
                    for(var i=0;i<6;i++){
                    this.DStr+="<tr align='center'>\n";
                    for(var j=0;j<7;j++){
                            var CS=new Date().getDate()==this.GetDateStr(y,m)[i*7+j]?"TdOver":"TdOut";
                            this.DStr+="<td id='TD' class='"+CS+"' cs='"+CS+"' onmouseover='this.className=\"TdOver\"' onmouseout='if(this.cs!=\"TdOver\")this.className=\"TdOut\"'  onmousedown='TableFunction().createPop()' onclick='TableFunction().AlertDay()'>"+this.GetDateStr(y,m)[i*7+j]+"</td>\n";
                            }
                    this.DStr+="</tr>\n";
                    }
                    this.DStr+="</tabe>";
                    return this.DStr;
                    }
            this.WriteSelect=function(obj,values,action,getobj){
                    if(values=="")return;
                    if(getobj){
                            obj.innerHTML=values+(action=="y"?" 年":" 月");
                            this.RewriteTableStr(YearTD.innerText.split(" ")[0],MonthTD.innerText.split(" ")[0]);
                            return false;
                            }
                    var StrArray=[];
                    if(action=="y"){
                            for(var i=0;i<15;i++){
                                    var year=values-7+i;
                                    StrArray[i]="<option value='"+year+"' "+(values==year?"selected":"")+"> "+year+"年</option>\n";
                                    }
                            obj.innerHTML="<select id='select1' style='width:67' onchange='TableFunction().WriteSelect(parentElement,this.value,\"y\",true)' onblur='YearTD.innerText=this.value+\" 年\"'>\n"+StrArray.join("")+"</select>";
                            select1.focus();
                            }
                    if(action=="m"){
                            for(var i=1;i<13;i++)
                                    StrArray[i]="<option value='"+i+"' "+(i==values?"selected":"")+"> "+i+"月</option>\n";
                            obj.innerHTML="<select id='select2' style='width:47' onchange='TableFunction().WriteSelect(parentElement,this.value,\"m\",true)' onblur='MonthTD.innerText=this.value+\" 月\"'>\n"+StrArray.join("")+"</select>";
                            select2.focus();
                            }
                    }
            this.RewriteTableStr=function(y,m){
                    var TArray=this.GetDateStr(y,m);
                    var len=TArray.length;
                    for(var i=0;i<len;i++){
                            TD[i].innerHTML=TArray[i];
                            TD[i].className="TdOut";
                            TD[i].cs="TdOut";
                            if(new Date().getYear()==y&&new Date().getMonth()+1==m&&new Date().getDate()==TArray[i]){
                                    TD[i].className="TdOver";
                                    TD[i].cs="TdOver";
                                    }
                            }
                    }
            this.JumpToRun=function(action){
                    var YearNO=YearTD.innerText.split(' ')[0];
                    var MonthNO=MonthTD.innerText.split(' ')[0];
                    if(action=="b"){
                            if(MonthNO=="1"){
                                    MonthNO=13;
                                    YearNO=YearNO-1;
                                    }
                            MonthTD.innerText=MonthNO-1+" 月";
                            YearTD.innerText=YearNO+" 年";
                            this.RewriteTableStr(YearNO,MonthNO-1);
                            }
                    if(action=="n"){
                            if(MonthNO=="12"){
                                    MonthNO=0;
                                    YearNO=YearNO-(-1);
                                    }
                            YearTD.innerText=YearNO+" 年";
                            MonthTD.innerText=MonthNO-(-1)+" 月";
                            this.RewriteTableStr(YearNO,MonthNO-(-1));
                            }
                    }
            this.AlertDay=function(){
                     if(event.srcElement.innerText!=" ")
                     alert(YearTD.innerText.split(' ')[0]+"年"+MonthTD.innerText.split(' ')[0]+"月"+event.srcElement.innerText+"日");
                     }
            this.createPop=function()
            {
             if(event.button==2)
             {
                     var oPopup = window.createPopup();
    var oPopupBody = oPopup.document.body;
    oPopupBody.innerHTML = "<div style='cursor:hand;background:buttonface;overflow:hidden;margin:0px;border:2px outset;' onclick=\"alert(\'"+YearTD.innerText.split(' ')[0]+"年"+MonthTD.innerText.split(' ')[0]+"月"+event.srcElement.innerText+"日"+"\')\">显示日期</div>";
    oPopup.show(100, 100, 80, 25, document.body);
             }
            }
            return this;
            }
            
    document.write(TableFunction().GetTableStr(new Date().getYear(),new Date().getMonth()+1));
    </script>
      

  2.   

    <style type="text/css">
    .body, td{
    font-family:"Arial";
    font-size:8pt;
    color:#000000;
    }
    .TrOut{
    border-left:1px solid #f4f4f4; border-right:1px solid #999999; border-top:1px solid #f4f4f4; border-bottom:1px solid #999999; background:#dddddd; height:26;}
    .TdOver{
    border-left:1px solid #9c9c9c; border-right:1px solid #ffffff; border-top:1px solid #9c9c9c; border-bottom:1px solid #ffffff; background:#eeeeee; height:20;}
    .TdOut{
    border-left:1px solid #ffffff; border-right:1px solid #9c9c9c; border-top:1px solid #ffffff; border-bottom:1px solid #9c9c9c; background:#eeeeee; height:20;}
    </style>
    <script language="JScript">
    function TableFunction(){
            this.GetDateStr=function(y,m){
                    this.DayArray=[];
                    for(var i=0;i<42;i++)this.DayArray[i]=" ";
                    for(var i=0;i<new Date(y,m,0).getDate();i++)this.DayArray[i+new Date(y,m-1,1).getDay()]=i+1;
                    return this.DayArray;
                    }
            this.GetTableStr=function(y,m){
                    
                    this.DateArray=["日","一","二","三","四","五","六"];
                    
                    this.DStr="<table oncontextmenu='return false' onselectstart='return false' style='width:160;cursor:default;border:1 solid #9c9c9c;border-right:0;border-bottom:0;filter:progid:dximagetransform.microsoft.dropshadow(color=#e3e3e3,offx=3,offy=3,positive=true)' border='0' cellpadding='0' cellspacing='0'>\n"+
                    "<tr><td colspan='7' class='TrOut'>"+
                    "<table width='100%' height='100%'border='0' cellpadding='0' cellspacing='0'><tr align='center'>\n"+
                    "<td width='20' style='font-family:\"webdings\";font-size:9pt' onclick='TableFunction().JumpToRun(\"b\")' onmouseover='this.style.color=\"#ff9900\"' onmouseout='this.style.color=\"\"'>3</td>\n"+
                    "<td id='YearTD' width='70' onmouseover='this.style.background=\"#cccccc\"' onmouseout='this.style.background=\"\"' onclick='TableFunction().WriteSelect(this,this.innerText.split(\" \")[0],\"y\",false)'>"+y+" 年</td>\n"+
                    "<td id='MonthTD' width='47' onmouseover='this.style.background=\"#cccccc\"' onmouseout='this.style.background=\"\"' onclick='TableFunction().WriteSelect(this,this.innerText.split(\" \")[0],\"m\",false)'>"+m+" 月</td>\n"+
                    "<td width='20' style='font-family:\"webdings\";font-size:9pt' onclick='TableFunction().JumpToRun(\"n\")' onmouseover='this.style.color=\"#ff9900\"' onmouseout='this.style.color=\"\"'>4</td></tr></table>\n"+
                    "</td></tr>\n"+
                    "<tr align='center'>\n";
                    for(var i=0;i<7;i++)
                    this.DStr+="<td class='TrOut'>"+DateArray[i]+"</td>\n";
                    this.DStr+="</tr>\n";
                    for(var i=0;i<6;i++){
                    this.DStr+="<tr align='center'>\n";
                    for(var j=0;j<7;j++){
                            var CS=new Date().getDate()==this.GetDateStr(y,m)[i*7+j]?"TdOver":"TdOut";
                            this.DStr+="<td id='TD' class='"+CS+"' cs='"+CS+"' onmouseover='this.className=\"TdOver\"' onmousedown='Reinfo()'onmouseout='if(this.cs!=\"TdOver\")this.className=\"TdOut\"' oncontextmenu = showMenu() onclick='TableFunction().AlertDay()'>"+this.GetDateStr(y,m)[i*7+j]+"</td>\n";
                            }
                    this.DStr+="</tr>\n";
                    }
                    this.DStr+="</tabe>";
                    return this.DStr;
                    }
            this.WriteSelect=function(obj,values,action,getobj){
                    if(values=="")return;
                    if(getobj){
                            obj.innerHTML=values+(action=="y"?" 年":" 月");
                            this.RewriteTableStr(YearTD.innerText.split(" ")[0],MonthTD.innerText.split(" ")[0]);
                            return false;
                            }
                    var StrArray=[];
                    if(action=="y"){
                            for(var i=0;i<15;i++){
                                    var year=values-7+i;
                                    StrArray[i]="<option value='"+year+"' "+(values==year?"selected":"")+"> "+year+"年</option>\n";
                                    }
                            obj.innerHTML="<select id='select1' style='width:67' onchange='TableFunction().WriteSelect(parentElement,this.value,\"y\",true)' onblur='YearTD.innerText=this.value+\" 年\"'>\n"+StrArray.join("")+"</select>";
                            select1.focus();
                            }
                    if(action=="m"){
                            for(var i=1;i<13;i++)
                                    StrArray[i]="<option value='"+i+"' "+(i==values?"selected":"")+"> "+i+"月</option>\n";
                            obj.innerHTML="<select id='select2' style='width:47' onchange='TableFunction().WriteSelect(parentElement,this.value,\"m\",true)' onblur='MonthTD.innerText=this.value+\" 月\"'>\n"+StrArray.join("")+"</select>";
                            select2.focus();
                            }
                    }
            this.RewriteTableStr=function(y,m){
                    var TArray=this.GetDateStr(y,m);
                    var len=TArray.length;
                    for(var i=0;i<len;i++){
                            TD[i].innerHTML=TArray[i];
                            TD[i].className="TdOut";
                            TD[i].cs="TdOut";
                            if(new Date().getYear()==y&&new Date().getMonth()+1==m&&new Date().getDate()==TArray[i]){
                                    TD[i].className="TdOver";
                                    TD[i].cs="TdOver";
                                    }
                            }
                    }
            this.JumpToRun=function(action){
                    var YearNO=YearTD.innerText.split(' ')[0];
                    var MonthNO=MonthTD.innerText.split(' ')[0];
                    if(action=="b"){
                            if(MonthNO=="1"){
                                    MonthNO=13;
                                    YearNO=YearNO-1;
                                    }
                            MonthTD.innerText=MonthNO-1+" 月";
                            YearTD.innerText=YearNO+" 年";
                            this.RewriteTableStr(YearNO,MonthNO-1);
                            }
                    if(action=="n"){
                            if(MonthNO=="12"){
                                    MonthNO=0;
                                    YearNO=YearNO-(-1);
                                    }
                            YearTD.innerText=YearNO+" 年";
                            MonthTD.innerText=MonthNO-(-1)+" 月";
                            this.RewriteTableStr(YearNO,MonthNO-(-1));
                            }
                    }
      

  3.   


            this.Reinfo=function()
            {
               document.all.selecctid1.innerText=YearTD.innerText.split(' ')[0]+"年"+MonthTD.innerText.split(' ')[0]+"月"+event.srcElement.innerText+"日";
              
            
            }
            this.AlertDay=function(){
                    if(event.srcElement.innerText!=" ")
                    {
                    }
         //alert();
                    }
            this.showMenu=function() 
             {
                 id="1"
                 menuForm.id.value = id;
               if("" == id)
                {  popMenu(itemMenu,200,"100");
                   }
                  else
                {  popMenu(itemMenu,200,"111");            }
                // 
               
                event.returnValue=false;
                 event.cancelBubble=true;
                 return false;         }
             
              this.popMenu=function(menuDiv,width,rowControlString)
             {
        //创建弹出菜单
        var pop=window.createPopup();
        //设置弹出菜单的内容
        pop.document.body.innerHTML=menuDiv.innerHTML;    //屏蔽菜单的菜单
        pop.document.oncontextmenu=function()
        {       return false;
        }
        //选择右键菜单的一项后,菜单隐藏
        pop.document.onclick=function()
        { pop.hide();    }  //显示菜单
        pop.show(event.clientX-1,event.clientY,width,1*25,document.body);
        return true;   }         
            return this;
            }      
            
            
            
    document.write(TableFunction().GetTableStr(new Date().getYear(),new Date().getMonth()+1));
    </script>
        <body>
            <form name = "menuForm" ID=Form1>
                <input type = "hidden" name = "id" value = "" ID=Hidden1>
                <table>
                </table>
          <!-- 这里用来定义需要显示的右键菜单 -->
        <div id="itemMenu" style="display:none">
               <table border="1" width="100%" height="100%" bgcolor="#cccccc" style="border:thin" cellspacing="0">
                      <tr>
                          <td style="cursor:default;border:outset 1;" align="center" id="selecctid1">
                          日期:
                          </td>
                      </tr>           </table>
        </div>        </form>
        </body>