您现在的位置: 军旅同心-旅游自驾-军旅文学 >> 读书赏析 >> 学习园地 >> 电脑网络 >> 技术文章 >> 正文
带日期标注的日历控件
作者:采集员 文章来源:来源于网络 点击数: 更新时间:2005-9-10 13:17:33
("TD");
  for (var i=0;i<tds.length;i++){
    if (tds(i) != object){
      tds(i).style.backgroundColor = tds(i).bgcolor;
      tds(i).style.color = ""
    }else{
      tds(i).style.backgroundColor = "navy";
      tds(i).style.color = "white";
    }
  }
}

function selectDate(){
  var i = parseInt(window.event.srcElement.innerText);
  if ((!isNaN(i)) && (i<3000)){
    hightLightDate(window.event.srcElement);
    activeDate.setFullYear(date.getFullYear(),date.getMonth(),i);
    sendEvent();
  }
}

function moveDate(){
  var k = window.event.keyCode;
  switch(k){
    case 37:
      activeDate.setFullYear(activeDate.getFullYear(),activeDate.getMonth(),activeDate.getDate()-1);
      break;
    case 38:
      activeDate.setFullYear(activeDate.getFullYear(),activeDate.getMonth(),activeDate.getDate()-7);
      break;
    case 39:
      activeDate.setFullYear(activeDate.getFullYear(),activeDate.getMonth(),activeDate.getDate()+1);
      break;
    case 40:
      activeDate.setFullYear(activeDate.getFullYear(),activeDate.getMonth(),activeDate.getDate()+7);
      break;
  }
  date.setFullYear(activeDate.getFullYear(),activeDate.getMonth(),activeDate.getDate());
  fillCalendar(date);
  sendEvent();
}

function setActiveDate(){
  var i = activeDate.getDate();
  activeDate.setFullYear(date.getFullYear(),date.getMonth(),i);
  while ((date.getMonth() != activeDate.getMonth()) || (date.getFullYear() != activeDate.getFullYear())){
    activeDate.setFullYear(date.getFullYear(),date.getMonth(),i--);
  }
  sendEvent();
}

function goNextMonth(){
  date.setMonth(date.getMonth()+1,1);
  setActiveDate();
  fillCalendar(date);
}

function goNextYear(){
  date.setFullYear(date.getFullYear()+1,date.getMonth(),1);
  setActiveDate();
  fillCalendar(date);
}

function goPriorYear(){
  date.setFullYear(date.getFullYear()-1,date.getMonth(),1);
  setActiveDate();
  fillCalendar(date);
}

function goPriorMonth(){
  date.setMonth(date.getMonth()-1,1);
  setActiveDate();
  fillCalendar(date);
}

//---------------------------------------------------------------------

var tbl = window.document.createElement("<TABLE style="border:solid 1px;width:100%;height:100%;font-size:9pt" cellspacing=0>");
var tblhd = window.document.createElement("THEAD");
var tblbd = window.document.createElement("TBODY");

var anchorPriorYear = window.document.createElement("A");
anchorPriorYear.style.fontFamily = "webdings";
anchorPriorYear.style.cursor = "hand";
anchorPriorYear.innerText = "7";
anchorPriorYear.title = "上一年";

var anchorPriorMonth = window.document.createElement("A");
anchorPriorMonth.style.fontFamily = "webdings";
anchorPriorMonth.style.cursor = "hand";
anchorPriorMonth.innerText = "3";
anchorPriorMonth.title = "上一月";

var anchorNextMonth = window.document.createElement("A");
anchorNextMonth.style.fontFamily = "webdings";
anchorNextMonth.style.cursor = "hand";
anchorNextMonth.innerText = "4";
anchorNextMonth.title = "下一月";

var anchorNextYear = window.document.createElement("A");
anchorNextYear.style.fontFamily = "webdings";
anchorNextYear.style.cursor = "hand";
anchorNextYear.innerText = "8";
anchorNextYear.title = "下一年";

var ynm = window.document.createElement("FONT");
ynm.style.width = "60%";
ynm.style.fontWeight = "bold";

var cpt = window.document.createElement("CAPTION");

tbl.appendChild(cpt);
tbl.appendChild(tblhd);
tbl.appendChild(tblbd);

function inithead(){
  cpt.style.backgroundColor = "navy";
  cpt.style.color = "white";
  cpt.style.textAlign = "center";
  cpt.style.cursor = "defalut";
  cpt.appendChild(anchorPriorYear);
  cpt.appendChild(anchorPriorMonth);
  cpt.appendChild(ynm);
  cpt.appendChild(anchorNextMonth);
  cpt.appendChild(anchorNextYear);
  var row = tblhd.insertRow();
  row.align = "center";
  var weekStr = new Array("日","一","二","三","四","五","六");
  for (var i=0;i<weekStr.length;i++){
    var cell = row.insertCell();
    cell.innerText = weekStr[i];
    cell.style.borderBottom = "solid 1px";
    cell.style.cursor = "default";
      cell.align = "center";
  }
}

function initbody(){
  for (var i=0;i<6;i++){
    var row = tblbd.insertRow();
    for (var j=0;j<7;j++){
      var cell = row.insertCell();
      cell.innerHTML = "&nbsp;";
      cell.style.cursor = "default";
      cell.align = "center";
    }
  }
}

function init(){
  inithead();
  initbody();
  element.appendChild(tbl);
  fillCalendar(date);
  tblbd.attachEvent("onclick",selectDate);
  tblbd.attachEvent("onkeydown",moveDate);
  anchorPriorYear.attachEvent("onclick",goPriorYear);
  anchorPriorMonth.attachEvent("onclick",goPriorMonth);
  anchorNextMonth.attachEvent("onclick",goNextMonth);
  anchorNextYear.attachEvent("onclick",goNextYear);
  sendEvent();
}
</script>

上一页  [1] [2] 


更多
免责声明:作品版权归所属媒体与作者所有!!本站刊载此文不代表同意其说法或描述,仅为提供更多信息。如果您认为我们侵犯了您的版权,请告知!本站立即删除。有异议请联系我们。
文章录入:烟灰缸    责任编辑:烟灰缸 
网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
| 设为首页 | 加入收藏 | 联系站长 | 友情链接 | 网站地图 | 版权申明 | 网站公告 | 管理登录 |