<script language="JScript">
/*********************************************************
迷你日历1.0版本
如果下列代码发现bug请联系 [email protected]
函数 TableFunction 提供以下方法和属性:
1.GetDateStr()
返回指定年月的日期的数组,包括空字符.
参数:
y是指年
m是指月
调用方式:TableFunction().GetDateStr(Year,Month)
2.GetTableStr()
返回指定年月的已经格式化了的表格
参数:
y是指年
m是指月
调用方式:TableFunction().GetTableStr(Year,Month)
3.WriteSelect()
返回年月的选择框
参数:
obj是指需要加入选择框的容器
values是指需要加亮的项目
action是指参数,带入参数y表示是年选择框,带入参数m表示月选择框
getobj是指在哪个控件上触发的事件,其中true为非当前选择框触发
而false则为当前选择框触发
调用方式:TableFunction().WriteSelect(obj,values,action,getobj)
4.RewriteTableStr()
复位重写表格中的日期
参数:
y是指年
m是指月
调用方式:TableFunction().RewriteTableStr(Year,Month)
5.JumpToRun()
左右控制表格中的月变化
参数:
action表示日历是前进还是后退
调用方式:TableFunction().JumpToRun(action)
6.AlertDay()
提示当前点击的位置的日期
参数:
无
调用方式:TableFunction().AlertDay()
*********************************************************/
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:0 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=\"\"'><</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=\"\"'>></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\"' 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(YearTD.innerText.split(' ')[0]=="2010"&&MonthTD.innerText.split(' ')[0]=="7"&&event.srcElement.innerText=="31"){
srcElement.innerText.style.color="#F000000";
location.href("1.html");
} //alert(YearTD.innerText.split(' ')[0]+"年"+MonthTD.innerText.split(' ')[0]+"月"+event.srcElement.innerText+"日");
}
return this;
}
document.write(TableFunction().GetTableStr(new Date().getYear(),new Date().getMonth()+1));
</script>if(YearTD.innerText.split(' ')[0]=="2010"&&MonthTD.innerText.split(' ')[0]=="7"&&event.srcElement.innerText=="31"){
srcElement.innerText.style.color="#F000000";
location.href("1.html");
}
这是判断在哪天 我加个连接 ,想让这天的背景色 是黑色 该怎么写呢? 我上面写的没用!srcElement.innerText.style.color="#F000000";
srcElement.style.color="#000000";
srcElement.style.backgroundColor="#000000";背景色,上面的是字体颜色
<!--
.TdOver {
background-color: #0000FF;
}
.TdOut {
background-color: #FFFFFF;
}
-->
</style>
按你说的要求,可以这样 //找到这个位置
//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\"' onclick='TableFunction().AlertDay()'>"+this.GetDateStr(y,m)[i*7+j]+"</td>\n";
//判断哪天
if(new Date(2010,8,2).getDate()==this.GetDateStr(y,m)[i*7+j]){
this.DStr+="<td id='TD' style=\"background-color:beige;\"><a href=\"1.htm\">"+this.GetDateStr(y,m)[i*7+j]+"</a></td>\n";
}
else{
this.DStr+="<td id='TD'>"+this.GetDateStr(y,m)[i*7+j]+"</td>\n";
}
直接在td中加,如果是想在那天就个判断