Jojoxx.net logotyp

 

 

Användare ikonAnvändare
Besökare just nu: 104
Snabblänkar ikonSnabblänkar
JavaScript-arkivet
Perl
FAQ

Sök på Jojoxx.net


Veckokalender

Exempel

Kod


<style type="text/css"> 
.calendertable { display:inline; }
.calendercell { width:70px;height:32px;font-size:11px;border:solid rgb(200,200,200) 1px;vertical-align:top;font-family:Arial;} 
.weekcell { height:10px;background-color:rgb(200,200,200);color:white; }
.todayscell { border:solid green 2px; } 
.datecell { }
.sundaycell { color:red; } 
.dateevent { font-style:italic;color:blue; }
</style> 

<script type="text/javascript"> 
/* Detta script finns att hämta på http://www.jojoxx.net och 
   får användas fritt så länge som dessa rader står kvar. */ 

var calenderdays=["","Måndag","Tisdag","Onsdag","Torsdag","Fredag","Lördag","Söndag"]; 
var dateevents=new Object();
dateevents["31/12-1999"]="Millenieskifte";
dateevents["24/12"]="Julafton";
dateevents["1"]="Ny månad";

Date.prototype.getWeek=function(){
	var nywd=(new Date(this.getFullYear(),0,1).getDay()==0)?7:new Date(this.getFullYear(),0,1).getDay();
	var w=Math.floor((this.getTime()-(new Date(this.getFullYear(),0,1).getTime()-(nywd-1)*86400000))/(604800000))+1
	if(nywd>4){w--;}
	if(w==0){ return new Date(this.getFullYear()-1,11,31).getWeek()}
	if(w==53 && new Date(this.getFullYear()+1,0,1).getDay()<=4){w=1}
	return w
}
function drawCalender(d){ 
   var now=new Date();
   var dwd=(d.getDay()==0)?7:d.getDay(); var html='<table class="calendertable" cellpadding="0" cellspacing="0">'; 
   html+='<tr><td class="calendercell weekcell">Vecka '+d.getWeek()+'</td></tr>';
   for(var n=1;n<=7;n++){ 
      var thisd=new Date(d.getTime()+(n-dwd)*86400000); 
      var thisdatestr=thisd.getDate()+'/'+(thisd.getMonth()+1);
      html+='<tr><td class="calendercell'; 
      if(thisd.getFullYear()==now.getFullYear()&&thisd.getMonth()==now.getMonth()&&thisd.getDate()==now.getDate()){html+=" todayscell";} 
      if(n-dwd==0){html+=" datecell";}
      if(n==7){html+=" sundaycell";} 
      html+='">'+thisdatestr+' '+calenderdays[n];
	  html+=((dateevents[thisdatestr+'-'+thisd.getFullYear()])?'<div class="dateevent">'+dateevents[thisdatestr+'-'+thisd.getFullYear()]+'</div>':'');
	  html+=((dateevents[thisdatestr])?'<div class="dateevent">'+dateevents[thisdatestr]+'</div>':'');
	  html+=((dateevents[thisd.getDate()])?'<div class="dateevent">'+dateevents[thisd.getDate()]+'</div>':'');
	  html+='</td></tr>';
   } 
   html+='</table>'; 
   document.write(html); 
}
drawCalender(new Date(new Date().getTime()-7*86400000)); 
drawCalender(new Date()); 
drawCalender(new Date(new Date().getTime()+7*86400000)); 
</script>

,