学习伴随一生
没有绝对,只有相对
<style type="text/css">        
        .CDclear {float:none;clear:both;height:0px;line-height:0px;overflow:hidden;font-size:1px;}
        .CDblank, .CDtdw, a.CDtda, a.CDtdas {display:block;width:20px;height:20px; line-height:20px; float:left; overflow:hidden; text-align:center; cursor:default;}
        .CDblank { overflow:hidden;font-size:1px;}
        .CDtdw   { }
        a.CDtda   { text-decoration:none; color:#444444;}        
        a.CDtdas  {text-decoration:none; color:#444444; background-color:#EFEFEF;}
        a.CDtda:hover ,a.CDtdas:hover { background-color:#FF9900;}
    </style>
    
    <script language="javascript" type="text/javascript">              
        //构造日历显示
        function GoQian(thisYear, thisMonth, thisDay) {
        
            var DaysCount = new Date(thisYear, thisMonth, 0).getDate(); //月的总天数

            var startDays = new Date(thisYear + '/' + thisMonth + '/1').getDay(); //月开始的天数是周几

            var goYearl = thisMonth == 1 ? thisYear - 1 : thisYear; //前翻的年
            var goYearr = thisMonth == 12 ? thisYear + 1 : thisYear; //后翻到年
            var goMonthl = thisMonth == 1 ? 12 : thisMonth - 1; //前翻的月
            var goMonthr = thisMonth == 12 ? 1 : thisMonth + 1; //后翻到月

            var weekDays = new Array('日', '一', '二', '三', '四', '五', '六');
            
            var br = '<br class="CDclear" />'; // 清除浮动

            var s = [];
            
            s.push('<table style="width:140px;" cellspacing="0" cellpadding="0">');            
            s.push('<tr>');
            s.push('<td style="width:20px;text-align:center;"><a href="javascript:GoQian(' + goYearl + ',' + goMonthl + ',' + thisDay + ');">&lt;</a></td>'); //上一月
            s.push('<td style="width:100px;text-align:center;">' + thisYear + '/' + thisMonth + '</td>');
            s.push('<td style="width:20px;text-align:center;"><a href="javascript:GoQian(' + goYearr + ',' + goMonthr + ',' + thisDay + ');">&gt;</a></td>'); //下一月
            s.push('</tr>');
            s.push('</table>');
            

            s.push('<div style="width:140px;">');
            //显示周数
            for (var j = 0; j < weekDays.length; j++) {
                s.push('<a class="CDtdw">' + weekDays[j] + '</a>');
            }
            s.push(br + '</div>');

            
            s.push('<div style="width:140px;">');
            //开始的空格构造
            for (var x = 0; x < startDays; x++) {
                s.push('<a class="CDblank"></a>');
            }
            
            //实际显示
            for (var y = startDays, ds = 1; ds <= DaysCount; y++) {
                s.push('<a class="' + (ds == thisDay ? 'CDtdas' : 'CDtda') + '" href="javascript:;" onclick="javascript:SetDateToControl(\'' + thisYear + '-' + thisMonth + '-' + ds + '\');">' + ds + '</a>');
                ds++;
            }
            s.push(br + '</div>');

            document.getElementById('Calendar1').innerHTML = s.join('');
            s.length = 0;
        }
        
        function SetDateToControl(arg){alert(arg)}

        var CurDate = new Date();
        var tDay = CurDate.getDate();
        var tMonth = CurDate.getMonth() + 1;  //0-11 实际月份要加一
        var tYear = CurDate.getFullYear();

        GoQian(tYear, tMonth, tDay);
        </script>

找日历的东东,不咋好用,索性自己弄个。这是最初原版,当个备份。
posted on 2009-09-28 14:40  蒋正  阅读(255)  评论(0编辑  收藏  举报