2010-3-20 优快云博客公告区取消使用脚本的功能的备份!

本文介绍了一个使用JavaScript实现的日历插件,该插件能够动态生成指定月份的日历,并支持用户通过前后翻页查看不同月份的日历。此外,插件还提供了日期聚焦功能和自定义链接设置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<script lnguage="Javascript">
function calendar(objName,name,date,width,height){
 this.objName=objName;
 this.calendarName=name!=null?name.toString():'calendar';
 this.width=width!=null?width:'100%';
 this.height=height!=null?height:'100%';
 this.dayName=['日','一','二','三','四','五','六'];
 this.nowDate=new Date();
 this.dateTime=date!=null?date:new Date();
 this.str='';
 this.dateTable='';
 this.days=31;
 this.pastDays=0;
 this.generated=false;

 this.generate=generate;
 this.getTable=getTable;
 this.focusDate=focusDate;
 this.attachLink=attachLink;
 this.refresh=refresh;
 this.previousMonth=previousMonth;
 this.nextMonth=nextMonth;
 this.setDate=setDate;
 this.afterRefresh=function(){};

 function generate(date){
  this.str='<table id="'+this.calendarName+'" class="cal" cellspacing="0" cellpadding="2" border="0" width="'
   +this.width+'" height="'
   +this.width+'"><tr><th onselectstart="return(false)"><font style="font-size:9pt">'
   +this.dayName.join('</th><th onselectstart="return(false)"><font style="font-size:9pt">')+'</font></th></tr>';
  this.dateTime=date!=null?new Date(date):this.dateTime;
  this.days=new Date(this.dateTime.getYear(),this.dateTime.getMonth()+1,0).getDate();
  this.pastDays=new Date(this.dateTime.getFullYear()+'/'+(this.dateTime.getMonth()+1)+'/1').getDay();
  this.str+='<tr><td colspan="7" id="'+this.calendarName+'Td" style="filter:blendtrans(duration=0.3)">';//滤镜,转换月份时的效果。
  this.getTable();
  this.str+=this.dateTable+'</td></tr></table>';
  this.generated=true;
  return this.str;
 }
 
 function getTable(){
  this.dateTable='<table width="100%" height="100%" cellspacing="2" cellpadding="1" class="caltb"><tr>'
   +new Array(this.pastDays+1).join('<td></td>');
  for(var i=1;i<=this.days;i++){
  var monthValue = (this.dateTime.getMonth()+1);
  if(monthValue <10) monthValue="0"+monthValue;
  var dayValue = i;
  if(i<10) dayValue ="0"+dayValue;
 
  var openurl = '<td id="'+this.calendarName+i+'">'+'<a href="http://blog.youkuaiyun.com/'+this.channel+'/archive/'+this.dateTime.getFullYear()+'/'+monthValue+'/'+dayValue+'.aspx">'+i+'</a></td>';
  var ropenurl = '<td id="'+this.calendarName+i+'">'+'<a href="http://blog.youkuaiyun.com/'+this.channel+'/archive/'+this.dateTime.getFullYear()+'/'+monthValue+'/'+dayValue+'.aspx"><font color="red">'+i+'</font></a></td>';
  var closeurl='<td id="'+this.calendarName+i+'">'+i+'</td>';
 
  if(this.dateTime.getFullYear() > this.nowDate.getFullYear())
  {
   this.dateTable+=closeurl;
  }
  else
  if(this.dateTime.getFullYear()== this.nowDate.getFullYear())
  {
   if(this.dateTime.getMonth() > this.nowDate.getMonth())
   {
    this.dateTable+=closeurl;
   }
   else
   if(this.dateTime.getMonth() == this.nowDate.getMonth())
   {
    if(i<=this.nowDate.getDate())
    {
     if(i == this.nowDate.getDate())
     {
      this.dateTable+=ropenurl;
     }
     else
     this.dateTable+=openurl;
    }
    else
    {
     this.dateTable+=closeurl;
    }
   }
   else
   {
    this.dateTable+=openurl;
   }
  }
  else
   this.dateTable+=openurl;
    if((i+this.pastDays)%7==0)this.dateTable+='</tr><tr>';
  }
  for(var i=1;i<=37-this.days-this.pastDays;i++){
   this.dateTable+='<td></td>';
   if((i+this.pastDays+this.days)%7==0)this.dateTable+='</tr><tr>';
  }
//控制条件,可以不显示某年某月前的日历(去掉注释即可)
//  if((this.dateTime.getFullYear()<=2004) && (this.dateTime.getMonth()<9))
//  {
//     this.dateTable+='<td><button hidefocus="true"><span>3</span></button></td>'
//   +'<td colspan="2">'+this.dateTime.getFullYear().toString().bold()+'</td>'
//   +'<td>'+(this.dateTime.getMonth()+1).toString().bold()+'</td>'
//   +'<td><button οnmοuseup="void('+this.objName+'.nextMonth())" hidefocus="true"><span>4</span></button></td>'
//   +'</tr></table>';
//  }
//  else
//  {
  this.dateTable+='<td><button οnmοuseup="void('+this.objName+'.previousMonth())" hidefocus="true"><span>3</span></button></td>'
   +'<td colspan="2">'+this.dateTime.getFullYear().toString().bold()+'</td>'
   +'<td>'+(this.dateTime.getMonth()+1).toString().bold()+'</td>'
   +'<td><button οnmοuseup="void('+this.objName+'.nextMonth())" hidefocus="true"><span>4</span></button></td>'
   +'</tr></table>';
//  }
  return this.dateTable;
 }
 function focusDate(date){
  try{
   eval(this.calendarName+(date!=null?date|0:new Date().getDate())+'.className="focus"');
   return(true);
  } catch(e) { return(false); }
 }
 function attachLink(date,link,target,title){
  try{
   eval(this.calendarName+(date!=null?date|0:new Date().getDate())
    +'.innerHTML="<a href=//"'+link+'//"'
    +' target=//"'+(target!=null?target:'_self')+'//"'
    +' title=//"'+(title!=null?title:'')+'//">'+date.toString()+'</a>"');
   return(true);
  } catch(e) { alert(e.message);return(false); }
 }
 function refresh(){
  try{
   eval(this.calendarName+'Td.filters[0].apply()');
   eval(this.calendarName+'Td.innerHTML=/''+this.getTable()+'/'');
   eval(this.calendarName+'Td.filters[0].play()');
   this.afterRefresh();
   return(true);
  } catch(e) { return(false); }
 }
 function previousMonth(){
  try{
   this.dateTime.setMonth(this.dateTime.getMonth()-1)
   this.generate();
   this.refresh();
   return(true);
  } catch(e) { return(false); }
 }
 function nextMonth(){
  try{
   this.dateTime.setMonth(this.dateTime.getMonth()+1)
   this.generate();
   this.refresh();
   return(true);
  } catch(e) { return(false); }
 }
 function setDate(dateStr){
  try{
   this.dateTime=new Date(dateStr);
   return(true);
  } catch(e) { return(false); }
 }
}
</script>
<div id="csdnCal" class="calendar">
<script lnguage="Javascript">
var csdnBlogCalendar=new calendar("csdnBlogCalendar","csdnBlogCal");
csdnBlogCalendar.channel='myid';//这里注意,请改成你的csdn blog的用户名!
document.write(csdnBlogCalendar.generate(null));
csdnBlogCalendar.focusDate();
</script>
</div>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值