📄 calindar.js
字号:
//L日历
var date_start,date_end,g_object
var today = new Date();
var separator="-";
var inover=false;
//mode :时间变换的类型0-年 1-月 2-直接选择月
function change_date(temp,mode)
{
var t_month,t_year
if (mode){
if(mode==1)
t_month=parseInt(cele_date_month.value,10)+parseInt(temp,10);
else
t_month=parseInt(temp)
if (t_month<cele_date_month.options(0).text) {
cele_date_month.value=cele_date_month.options(cele_date_month.length-1).text;
change_date(parseInt(cele_date_year.value,10)-1,0);
}
else{
if (t_month>cele_date_month.options(cele_date_month.length-1).text){
cele_date_month.value=cele_date_month.options(0).text;
change_date(parseInt(cele_date_year.value,10)+1,0);
}
else
{cele_date_month.value=t_month;
set_cele_date(cele_date_year.value,cele_date_month.value);
}
}
}
else{
t_year=parseInt(temp,10);
if (t_year<cele_date_year.options(0).text) {
cele_date_year.value=cele_date_year.options(0).text;
set_cele_date(cele_date_year.value,1);
}
else{
if (parseInt(t_year,10)>parseInt(cele_date_year.options(cele_date_year.length-1).text,10)){
cele_date_year.value=cele_date_year.options(cele_date_year.length-1).text;
set_cele_date(cele_date_year.value,12);
}
else
{cele_date_year.value=t_year;
set_cele_date(cele_date_year.value,cele_date_month.value);
}
}
}
window.cele_date.focus();
}
//初始化日历
function init(d_start,d_end)
{
var temp_str;
var i=0
var j=0
date_start=new Date(1980,7,1)
date_end=new Date(2004,8,1)
document.writeln("<div name=\"cele_date\" id=\"cele_date\" style=\"display:none\" style=\"LEFT: 69px; POSITION: absolute; TOP: 159px; float:left; background-Color: lightblue; margin: 0px 0 0 0px;Z-INDEX:99\" onClick=\"event.cancelBubble=true;\" onBlur=\"hilayer()\" onMouseover=\"getlayerfocus()\" onMouseout=\"lostlayerfocus()\">-</div>");
window.cele_date.innerHTML="";
//temp_str="<table border=\"1\" cellPadding=\"0\" cellSpacing=\"2\" style=\" margin: 1px 2 2 1px; padding: 0px;\" bgcolor=\"#F6F8F9\" width=\"231\" bordercolor=\"#154D8C\">";
//temp_str="<div id=\"cele_date_iframe\" style=\"height:200;width:200;overflow:hidden;\"><iframe height=\"100%\" width=\"100%\" frameborder=\"0\"></iframe></div><div style=\"POSITION: absolute; top:0;left:0; z-index:100;background-image: url(hr/ibg6.gif);\"><table border=\"1\" bgcolor=\"#DDDDDD\" bordercolor=\"white\"><tr><td colspan=7 onmouseover=\"overcolor(this)\">";
temp_str="<div id=\"cele_date_iframe\" style=\"height:200;width:200;overflow:hidden;\"><iframe height=\"100%\" width=\"100%\" frameborder=\"0\"></iframe></div><div id=\"cele_date_main\" style=\"POSITION: absolute; top:0;left:0; z-index:100;\"><table border=\"1\" cellPadding=\"0\" cellSpacing=\"2\" style=\" margin: 1px 2 2 1px; padding: 0px; width: 231px;\" bgcolor=\"#F6F8F9\" bordercolor=\"#154D8C\">";
temp_str+="<tr style=\"font-size:12px;\">";
//temp_str+="<td colspan=1><input type=\"Button\" value=\"<\" style=\"width:100%; background-color: #f1f1f1; border:1 ridge #ffffff;\"></td>";
temp_str+="<td colspan=1><input type=\"Button\" value=\"<\" onclick=\"change_date(-1,1)\" onmouseover=\"overbtn(this)\" onmouseout=\"outbtn(this)\" style=\"width:100%; border:1 ridge #ffffff; background-color:#f1f1f1; cursor: hand\"></td>";
temp_str+=""
temp_str+="<td colspan=3 align=\"center\"><select name=\"cele_date_year\" id=\"cele_date_year\" style=\"width:60%;font-size:12px\" language=\"javascript\" onchange=\"change_date(this.value,0)\" onmouseover=\"getlayerfocus()\" onblur=\"getlayerfocus()\" style=\"border: 0px #666666 outset; background-color: #F6F8F9\">"
for (i=1900;i<=2020;i++)
{
temp_str+="<OPTION value=\""+i.toString()+"\">"+i.toString()+"</OPTION>";
}
temp_str+="</select>";
temp_str+=""
temp_str+="<select name=\"cele_date_month\" id=\"cele_date_month\" style=\"width:40%;font-size:12px\" language=\"javascript\" onchange=\"change_date(this.value,2)\" onmouseover=\"getlayerfocus()\" onblur=\"getlayerfocus()\" style=\"border: 0px #666666 outset; background-color: #F6F8F9\">"
for (i=1;i<=12;i++)
{
temp_str+="<OPTION value=\""+i.toString()+"\">"+i.toString()+"</OPTION>";
}
temp_str+="</select></td>";
temp_str+=""
temp_str+="<td colspan=1><input type=\"Button\" value=\">\" onclick=\"change_date(1,1)\" onmouseover=\"overbtn(this)\" onmouseout=\"outbtn(this)\" style=\"width:100%; border:1 ridge #ffffff; background-color:#f1f1f1; cursor: hand\"></td>";
//temp_str+="<td colspan=1><input type=\"Button\" value=\">\" style=\"width:100%; background-color: #f1f1f1; border:1 ridge #ffffff;\"></td>";
//A4CCFA 蓝 #76BEB6 绿
//temp_str+="<td colspan=2 name=\"today2\" id=\"today2\" align=\"center\" style=\"background-color:#B4E2E2; cursor:hand;\" onclick=\"today_click()\" onmouseover=\"getlayerfocus()\" onmouseout=\"getlayerfocus()\">?</td>" //#B4E2E2 浅绿 99CCCC 深
temp_str+="<td colspan=2><input type=\"Button\" name=\"today2\" id=\"today2\" value=\"?\" onclick=\"today_click()\" onmouseover=\"overbtn(this)\" onmouseout=\"outbtn(this)\" style=\"width:100%; border:1 ridge #ffffff; background-color:#f1f1f1; cursor: hand\"></td>"
temp_str+="</tr><tr height=\"18\" align=\"center\" bgcolor=\"#A4CCFA\" style=\"font-size:12px\" onmouseover=\"overcolor(this)\"><td>"
temp_str+="<font color=red>日</font></td><td>";temp_str+="一</td><td>"; temp_str+="二</td><td>"; temp_str+="三</td><td>"
temp_str+="四</td><td>";temp_str+="五</td><td>"; temp_str+="<font color=red>六</font></td></tr>";
for (i=1 ;i<=6 ;i++)
{
temp_str+="<tr height=\"15\">";
temp_str+="<td name=\"c"+i+"_1\"id=\"c"+i+"_1\" align=\"center\" style=\"COLOR: #000000; font-size: 12px\" language=\"javascript\" onmouseover=\"overcolor(this)\" onmouseout=\"outsun(this)\" onclick=\"td_click(this)\">?</td>"
for(j=2;j<=6;j++){
temp_str+="<td name=\"c"+i+"_"+j+"\"id=\"c"+i+"_"+j+"\" align=\"center\" style=\"COLOR: #000000; font-size: 12px\" language=\"javascript\" onmouseover=\"overcolor(this)\" onmouseout=\"outcolor(this)\" onclick=\"td_click(this)\">?</td>"
}
temp_str+="<td name=\"c"+i+"_7\"id=\"c"+i+"_7\" align=\"center\" style=\"COLOR: #000000; font-size: 12px\" language=\"javascript\" onmouseover=\"overcolor(this)\" onmouseout=\"outsun(this)\" onclick=\"td_click(this)\">?</td>"
temp_str+="</tr>"
}
temp_str+="</td></tr></table>";
window.cele_date.innerHTML=temp_str;
}
function set_cele_date(year,month)
{
var i,j,p,k
var nd=new Date(year,month-1,1);
event.cancelBubble=true;
cele_date_year.value=year;
cele_date_month.value=month;
k=nd.getDay()-1
var temp;
for (i=1;i<=6;i++)
for(j=1;j<=7;j++)
{
eval("c"+i+"_"+j+".innerHTML=\"\"");
eval("c"+i+"_"+j+".bgColor=\"\""); //#F6F8F9灰白
eval("c"+i+"_"+j+".style.cursor=\"\"");
}
while(month-1==nd.getMonth())
{ j=(nd.getDay() +1);
p=parseInt((nd.getDate()+k) / 7)+1;
eval("c"+p+"_"+j+".innerHTML="+"\""+nd.getDate()+"\"");
if (nd.getDate()>1 || nd.getDate()<31)
{
eval("c"+p+"_"+j+".bgColor=\"#ffffff\"");
eval("c"+p+"_"+j+".style.border=\"1 solid #cccccc\"");
eval("c"+p+"_"+j+".style.cursor=\"hand\"");
}
if (nd.getDay()==0||nd.getDay()==6)
{
eval("c"+p+"_"+j+".bgColor=\"#FB8A8A\"");
}
if ((nd.getDate()==today.getDate())&&(cele_date_month.value==today.getMonth()+1)&&(cele_date_year.value==today.getYear())){
eval("c"+p+"_"+j+".bgColor=\"#FEFDC9\"");//#A4CCFA FFAEB9 绿76BEB6
eval("c"+p+"_"+j+".style.border=\"1 outset #bbbbbb\"");
//eval("c"+p+"_"+j+".onmouseover=\"\"");
eval("c"+p+"_"+j+".onmouseout=\"\"");
//eval("today2.innerHTML="+"\""+(nd.getMonth()+1)+"-"+nd.getDate()+"\"");
eval("today2.value="+"\""+(nd.getMonth()+1)+"-"+nd.getDate()+"\"");
}
if (nd>date_end || nd<date_start)
{
eval("c"+p+"_"+j+".bgColor=\"#FF9999\"");
eval("c"+p+"_"+j+".style.cursor=\"text\"");
}
nd=new Date(nd.valueOf() + 86400000)
}
}
/*****************************************************************/
/**
*显示日历控件
* example:
* <input type="text" name="tse" onclick="showCalindar(this)">
*/
function showCalindar(textnode){
if(textnode.tagName == 'INPUT' && textnode.type.toLowerCase() == 'text'){
show_cele_date(textnode, '', '', textnode);
}else{
alert('只适用于文本框节点!');
return;
}
}
//s_object:点击的对象;d_start-d_end有效的时间区段;需要存放值的控件;
function show_cele_date(eP,d_start,d_end,t_object)
{
window.cele_date.style.display="";
window.cele_date.style.zIndex=99
var s,cur_d
var eT = eP.offsetTop;
var eH = eP.offsetHeight+eT;
var dH = window.cele_date.style.pixelHeight;
var sT = document.body.scrollTop;
var sL = document.body.scrollLeft;
event.cancelBubble=true;
window.cele_date.style.posLeft = event.clientX-event.offsetX+sL-5;
window.cele_date.style.posTop = event.clientY-event.offsetY+eH+sT-40;
window.cele_date_iframe.style.height = window.cele_date_main.clientHeight
window.cele_date_iframe.style.width = window.cele_date_main.clientWidth
if (window.cele_date.style.posLeft+window.cele_date.clientWidth>document.body.clientWidth) window.cele_date.style.posLeft+=eP.offsetWidth-window.cele_date.clientWidth;
//if (window.cele_date.style.posTop+window.cele_date.clientHeight>document.body.clientHeight) window.cele_date.style.posTop+=eP.offsetHeight-window.cele_date.clientHeight-eH-dH-10;
if (d_start!=""){
if (d_start=="today"){
date_start=new Date(today.getYear(),today.getMonth(),today.getDate());
}else{
s=d_start.split(separator);
date_start=new Date(s[0],s[1]-1,s[2]);
}
}else{
date_start=new Date(1900,1,1);
}
if (d_end!=""){
s=d_end.split(separator);
date_end=new Date(s[0],s[1]-1,s[2]);
}else{
date_end=new Date(3000,1,1);
}
g_object=t_object
cur_d=new Date()
set_cele_date(cur_d.getYear(),cur_d.getMonth()+1);
window.cele_date.style.display="block";
//window.cele_date.focus();
/*5555***********************************************************************************************************
var wid;
//wid = cele_date.innerWidth
wid = window.cele_date_maint.clientWidth
alert(wid);
hid = window.cele_date_maint.clientHeight
alert(hid);
*/
}
function td_click(t_object)
{
var t_d
if (parseInt(t_object.innerHTML,10)>=1 && parseInt(t_object.innerHTML,10)<=31 )
{
t_d=new Date(cele_date_year.value,cele_date_month.value-1,t_object.innerHTML)
if (t_d<=date_end && t_d>=date_start)
{
var year = cele_date_year.value;
var month = cele_date_month.value;
var day = t_object.innerHTML;
if (parseInt(month)<10) month = "0" + month;
if (parseInt(day)<10) day = "0" + day;
g_object.value=year+separator+month+separator+day;
window.cele_date.style.display="none";
};
}
}
function today_click()
{
var t_d=new Date()
if (t_d<=date_end && t_d>=date_start)
{
var year = t_d.getYear();
var month = t_d.getMonth()+1;
var day = t_d.getDate();
if (parseInt(month)<10) month = "0" + month;
if (parseInt(day)<10) day = "0" + day;
g_object.value=year+separator+month+separator+day;
window.cele_date.style.display="none";
};
}
function h_cele_date()
{
window.cele_date.style.display="none";
}
/*function overcolor(obj)
{
if (obj.style.cursor=="hand") obj.style.color = "#FFFFFF";
inover=true;
window.cele_date.focus();
}
function outcolor(obj)
{
obj.style.color = "#000000";
inover=false;
}*/
function overcolor(obj)
{
if (obj.style.cursor=="hand"){ //obj.style.background-color = "#FEFDC9";
eval("obj.bgColor=\"#FEFDC9\"");
eval("obj.style.border=\"1 outset #bbbbbb\"");
}
inover=true;
window.cele_date.focus();
}
function overbtn(obj)
{
eval("obj.style.cssText=\"background-color: #dddddd; width:100%; border:1 ridge #ffffff; cursor: hand\"");
inover=true;
window.cele_date.focus();
}
function outbtn(obj)
{
eval("obj.style.cssText=\"width:100%; border:1 ridge #ffffff; background-color:#f1f1f1; cursor: hand\"");
inover=false;
}
function outcolor(obj)
{
if (obj.style.cursor=="hand"){
eval("obj.bgColor=\"#ffffff\"");
eval("obj.style.border=\"1 solid #cccccc\"");
}
inover=false;
}
function outsun(obj)
{
//obj.style.color = "#000000";
if (obj.style.cursor=="hand"){
eval("obj.bgColor=\"#FB8A8A\"");
eval("obj.style.border=\"1 solid #dcdcdc\"");
}
inover=false;
}
/*function outtoday(obj)
{
//obj.style.color = "#000000";
if (obj.style.cursor=="hand"){
eval("obj.bgColor=\"#76BEB6\"");
eval("obj.style.border=\"1 solid #dcdcdc\"");
}
inover=false;
}*/
function getNow(o){
var Stamp=new Date();
var year = Stamp.getYear();
var month = Stamp.getMonth()+1;
var day = Stamp.getDate();
if(month<10){
month="0"+month;
}
if(day<10){
day="0"+day;
}
o.value=year+separator+month+separator+day;
}
function hilayer()
{
if (inover==false)
{
var lay=document.all.cele_date;
lay.style.display="none";
}
}
function getlayerfocus()
{
inover=true;
}
function lostlayerfocus()
{
inover=false;
}
init();
//日历结束
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -