自己写了个JS日历



var dayArray = new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");  //创建星期数组
var today = new Date();



window.onload = function(){
var tabletag = document.createElement("table");
tabletag.id = "dateform";
var oTable = document.body.appendChild(tabletag);
var i = j = 0;

var oRows = oTable.insertRow(i);
for(j=0;j<7;j++){
var oCols = oRows.insertCell(j)//FF
oCols.innerHTML = dayArray[j];
oCols.style.background="yellow"
}
i++;
for(;i<6;i++){
oRows=oTable.insertRow(i)//FF
//var oRows = oTable.appendChild();
for(j=0;j<7;j++){
var oCols = oRows.insertCell(j)//FF
//oCols.innerHTML = i + "行" + j +"列";
oCols.style.background="#eee"
}
  }

var plas = getDayOfWeek(today.getYear(),today.getMonth() + 1,1);
var mondays = DayNumOfMonth(today.getYear(),today.getMonth() + 1);

for(i=1;i<=mondays;i++)
{

var rnum = (plas + i)/7;
if(rnum>parseInt(rnum))
rnum = parseInt(rnum) + 1;
else
rnum = rnum;
//alert(rnum);
//oRows = oTable.getRow(rnum);
var cnum = getDayOfWeek(today.getYear(),today.getMonth() + 1,i);
//var oCols = oRows.getCell(cnum);
oTable.rows[rnum].cells[cnum].innerHTML = i;



oTable.rows[rnum].cells[cnum].onmouseover = function(){this.style.background="green"};

oTable.rows[rnum].cells[cnum].onmouseout = function(){this.style.background="#eee";};
if(i==today.getDate())
{
oTable.rows[rnum].cells[cnum].style.background="red"
oTable.rows[rnum].cells[cnum].onmouseout = function(){this.style.background="red";};
}

//oTable.rows[rnum].cells[cnum].setAttribute("onclick", dblclick(rnum,cnum));;
}

}


   this.dblclick = function(i,j){
alert(i + "," + j);
}

    //alert(getDayOfWeek(day.getYear(),2,1));  //调用判断星期几的方法


//alert(DayNumOfMonth(2012,02));
function DayNumOfMonth(Year,Month)
{
    var d = new Date(Year,Month,0);
    return d.getDate();
}

function getDayOfWeek(Year,Month,Day){
var dayValue = Year + "-" + Month + "-" + Day;
    var day = new Date(Date.parse(dayValue.replace(/-/g, '/')));   //将日期值格式化
    return day.getDay();  //返一个星期中的某一天,其中0为星期日
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值