?? calendar.js
字號:
//origin from help.js
document.onload = helpInit();
document.write('<iframe style="position:absolute;top:-2000;left:-2000;z-index:9" id="help_frm" border="0" frameborder="0"></iframe>');
function helpInit() {
var list = document.all.tags("BUTTON");
for(var i = 0;i < list.length;i++) {
if(list[i].getAttribute("target") != null) {
var target = document.getElementById(list[i].getAttribute("target"));
if(!target) {
list[i].style.display = "none";
continue;
}
list[i].attachEvent("onclick",helper);
var _id = list[i].getAttribute("id");
var targetName = _id.substring(0,_id.length-4);
if(list[i].getAttribute("multi") == "done") {
var _ls2 = document.all(_id);
for(var j = 0;j<_ls2.length;j++) {
_ls2[j].setAttribute("multi","yes");
_ls2[j].setAttribute("target",targetName);
}
var _ls1 = document.all.tags("INPUT");
for(var j = 0;j<_ls1.length;j++) {
if(_ls1[j].getAttribute("id").substring(0,targetName.length) == targetName) {
_ls1[j].setAttribute("id",targetName);
}
}
}
if(list[i].getAttribute("multi") == "yes") {
var ls1 = document.all(targetName);
var ls2 = document.all(_id);
for(var j = 0;j<ls1.length;j++) {
ls1[j].setAttribute("id",targetName + "_" + j);
}
for(var j = 0;j<ls2.length;j++) {
ls2[j].setAttribute("multi","done");
ls2[j].setAttribute("target",targetName + "_" + j);
}
}
}
}
}
function helper() {
try {
with(event.srcElement) {
if(!document.getElementById(getAttribute("target"))) return;
var width = 240;
var height = 208;
var offset = 0;
if ( document.body.clientWidth < ( 260 + util.getElementLeft(event.srcElement) ) ) {
offset = util.getElementLeft(event.srcElement)-width;
} else {
offset = util.getElementLeft(event.srcElement);
}
switch(getAttribute("pattern")) {
case "date":
help_date(width,height,offset,util.getElementTop(event.srcElement),getAttribute("target"),"yyyy-MM-dd");
break;
case "date_time":
help_date(width,height,offset,util.getElementTop(event.srcElement),getAttribute("target"),"yyyy-MM-dd HH:mm:ss");
break;
case "time":
help_date(width,height,offset,util.getElementTop(event.srcElement),getAttribute("target"),"HH:mm:ss");
break;
case "year_month":
help_date(width,height,offset,util.getElementTop(event.srcElement),getAttribute("target"),"yyyy-MM");
break;
case "hour_minute":
help_date(width,height,offset,util.getElementTop(event.srcElement),getAttribute("target"),"HH:mm");
break;
case "minute":
help_date(width,height,offset,util.getElementTop(event.srcElement),getAttribute("target"),"yyyy-MM-dd HH:mm");
break;
}
}
}
catch (e){}
}
/* 作用:日期輸入對話框
*
*/
function help_date(WndWidth,WndHeight,WndLeft,WndTop,target,format,self) {
var sep = "\r\n";
var script = "<script language=\"JavaScript\">"
+ sep + "function Initial() {"
+ sep + "try {"
+ sep + " var myDate = new Date();"
+ sep + " if(parent.validateDateEx(parent.document.getElementById(\"" + target + "\").value,\"yyyy-MM-dd\")) {"
+ sep + " myDate = parent.newDate(parent.document.getElementById(\"" + target + "\").value,\"yyyy-MM-dd\");"
+ sep + " }"
+ sep + " myYear.value = myDate.getFullYear() + \"年\";"
+ sep + " var coll = myMonth.children;"
+ sep + " for(var i = 0;i < coll.length;i++) {"
+ sep + " if(coll[i].value == myDate.getMonth() + 1) {"
+ sep + " coll[i].selected = \"true\";"
+ sep + " break;"
+ sep + " }"
+ sep + " }"
+ sep + " sel_day = myDate.getDate();"
+ sep + " setCalendar();"
+ sep + " setTime();"
+ sep + "}catch(e){}"
+ sep + "}"
+ sep + "var timer;"
+ sep + "function setTime() {"
+ sep + " var Now = new Date();"
+ sep + " myHour.value = parent.hour(Now);"
+ sep + " myMinute.value = parent.minute(Now);"
+ sep + " mySecond.value = parent.second(Now);"
+ sep + " timer = window.setTimeout(setTime,1000);"
+ sep + "}"
+ sep + "function setCalendar() {"
+ sep + " if(!checkYear()) return;"
+ sep + " for(var i = 0;i < 42;i++) {"
+ sep + " document.getElementById(\"day_\" + i).innerText = String.fromCharCode(32);"
+ sep + " }"
+ sep + " var myDate = new Date(document.getElementById(\"myYear\").value.substring(0,4),parseInt(document.getElementById(\"myMonth\").value) - 1,1);"
+ sep + " var day_count = parent.getDays(myDate);"
+ sep + " for(var i = 1;i <= day_count;i++) {"
+ sep + " document.getElementById(\"day_\" + (myDate.getDay() + i - 1)).innerText = i;"
+ sep + " }"
+ sep + " if(sel_day > day_count) sel_day = day_count;"
+ sep + " setDay(document.getElementById(\"day_\" + (parseInt(sel_day) + myDate.getDay() - 1)));"
+ sep + "}"
+ sep + "var sel_id = \"day_0\";"
+ sep + "var sel_day = 1;"
+ sep + "function setDay(obj) {"
+ sep + " if(isNaN(obj.innerText) || obj.innerText == \" \") return;"
+ sep + " document.getElementById(sel_id).style.border = \"1px solid white\";"
+ sep + " document.getElementById(sel_id).style.background = \"white\";"
+ sep + " obj.style.border = \"1px solid black\";"
+ sep + " obj.style.background = \"#EEEEEE\";"
+ sep + " sel_id = obj.id;"
+ sep + " sel_day = obj.innerText;"
+ sep + "}"
+ sep + "function help_date_cancel() {"
+ sep + " window.clearTimeout(timer);"
+ sep + " parent.help_cancel(\'" + target + "\',0," + self + ")"
+ sep + "}"
+ sep + "var util = new parent.Utility()"
+ sep + "function help_date_ok() {"
+ sep + " window.clearTimeout(timer);"
+ sep + " if(!checkYear()) {"
+ sep + " alert(\"年份輸入錯誤,請修改!\");"
+ sep + " myYear.focus();"
+ sep + " return;"
+ sep + " }"
+ sep + " if(!util.isNum(myHour.value,0,23)) {"
+ sep + " alert(\"時間輸入錯誤,請修改!\");"
+ sep + " myHour.focus();"
+ sep + " return;"
+ sep + " }"
+ sep + " if(!util.isNum(myMinute.value,0,59)) {"
+ sep + " alert(\"時間輸入錯誤,請修改!\");"
+ sep + " myMinute.focus();"
+ sep + " return;"
+ sep + " }"
+ sep + " if(!util.isNum(mySecond.value,0,59)) {"
+ sep + " alert(\"時間輸入錯誤,請修改!\");"
+ sep + " mySecond.focus();"
+ sep + " return;"
+ sep + " }"
+ sep + " var myDate = new Date(document.getElementById(\"myYear\").value.substring(0,4),parseInt(document.getElementById(\"myMonth\").value) - 1,1);"
+ sep + " myDate.setDate(parseInt(sel_id.split(\"_\")[1]) - myDate.getDay() + 1);"
+ sep + " myDate.setHours(parseInt(myHour.value),parseInt(myMinute.value),parseInt(mySecond.value));"
+ sep + " parent.document.getElementById(\"" + target + "\").value = parent.formatDate(myDate,\"" + format + "\");"
+ sep + " try {"
+ sep + " parent.document.getElementById(\"" + target + "_LBL\").innerText = parent.formatDate(myDate,\"" + format + "\");"
+ sep + " } catch(e) {}"
+ sep + " parent.help_cancel(\"" + target + "\",1," + self + ");"
+ sep + "}"
+ sep + "function checkYear() {"
+ sep + " if(document.getElementById(\"myYear\").value.length < 4) return false;"
+ sep + " if(isNaN(document.getElementById(\"myYear\").value.substring(0,4))) return false;"
+ sep + " if(parseInt(document.getElementById(\"myYear\").value.substring(0,4)) < 1900) return false;"
+ sep + " if(parseInt(document.getElementById(\"myYear\").value.substring(0,4)) > 2100) return false;"
+ sep + " return true;"
+ sep + "}"
+ sep + "function addYear() {"
+ sep + " if(!checkYear()) return;"
+ sep + " document.getElementById(\"myYear\").value = parseInt(document.getElementById(\"myYear\").value.substring(0,4)) + 1 + \"年\";"
+ sep + "}"
+ sep + "function decYear() {"
+ sep + " if(!checkYear()) return;"
+ sep + " document.getElementById(\"myYear\").value = parseInt(document.getElementById(\"myYear\").value.substring(0,4)) - 1 + \"年\";"
+ sep + "}"
+ sep + "var time_span = null;"
+ sep + "function setTimeSpan(obj) {"
+ sep + " window.clearTimeout(timer);"
+ sep + " time_span = obj;"
+ sep + "}"
+ sep + "function addTime() {"
+ sep + " window.clearTimeout(timer);"
+ sep + " if(time_span) {"
+ sep + " var type = \"\";"
+ sep + " switch(time_span.id) {"
+ sep + " case \"myHour\":"
+ sep + " type = \"hour\";"
+ sep + " break;"
+ sep + " case \"myMinute\":"
+ sep + " type = \"minute\";"
+ sep + " break;"
+ sep + " case \"mySecond\":"
+ sep + " type = \"second\";"
+ sep + " break;"
+ sep + " }"
+ sep + " time_span.value = parent.addTime(time_span.value,type);"
+ sep + " }"
+ sep + "}"
+ sep + "function decTime() {"
+ sep + " window.clearTimeout(timer);"
+ sep + " if(time_span) {"
+ sep + " var type = \"\";"
+ sep + " switch(time_span.id) {"
+ sep + " case \"myHour\":"
+ sep + " type = \"hour\";"
+ sep + " break;"
+ sep + " case \"myMinute\":"
+ sep + " type = \"minute\";"
+ sep + " break;"
+ sep + " case \"mySecond\":"
+ sep + " type = \"second\";"
+ sep + " break;"
+ sep + " }"
+ sep + " time_span.value = parent.decTime(time_span.value,type);"
+ sep + " }"
+ sep + "}"
+ sep + "Initial();"
+ sep + "var _dx,_dy; // 鼠標起始坐標"
+ sep + "var _ox,_oy; // 層起始坐標"
+ sep + "function Drag() {"
+ sep + " with(event.srcElement) {"
+ sep + " attachEvent(\"onmousemove\", doDrag);"
+ sep + " attachEvent(\"onmouseup\", endDrag);"
+ sep + " attachEvent(\"onmouseout\", endDrag);"
+ sep + " attachEvent(\"onlosecapture\", endDrag);"
+ sep + " setCapture();"
+ sep + " }"
+ sep + " window.event.cancelBubble = true;"
+ sep + " _dx = event.screenX;"
+ sep + " _dy = event.screenY;"
+ sep + " with(parent.document.getElementById(\"help_frm\")) {"
+ sep + " _ox = parseInt(style.left);"
+ sep + " _oy = parseInt(style.top);"
+ sep + " }"
+ sep + "}"
+ sep + "function doDrag() {"
+ sep + " with(parent.document.getElementById(\"help_frm\")) {"
+ sep + " style.left = (event.screenX - _dx + _ox);"
+ sep + " style.top = (event.screenY - _dy + _oy);"
+ sep + " }"
+ sep + "}"
+ sep + "function endDrag() {"
+ sep + " with(event.srcElement) {"
+ sep + " detachEvent(\"onmousemove\", doDrag);"
+ sep + " detachEvent(\"onmouseup\", endDrag);"
+ sep + " detachEvent(\"onmouseout\", endDrag);"
+ sep + " detachEvent(\"onlosecapture\", endDrag);"
+ sep + " releaseCapture();"
+ sep + " }"
+ sep + "}"
+ sep + "</script>";
var html = "<html>"
+ sep + "<head>"
+ sep + "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\">"
+ sep + "<style>"
+ sep + "td{font-family:\"宋體\";font-size:9pt}"
+ sep + "font{font-family:\"宋體\";font-size:9pt}"
+ sep + "span{font-family:\"宋體\";font-size:9pt}"
+ sep + "input{font-family:\"宋體\";font-size:9pt;padding:1px 0px 0px 2px}"
+ sep + "select{font-family:\"宋體\";font-size:9pt}"
+ sep + "button{font-family:\"宋體\";font-size:9pt;padding:0px 0px 0px 0px;height:19px}"
+ sep + ".box1{background:#EEEEEE;border-style:none solid solid none;border-color:black;border-width:1px;padding:3px 0px 0px 0px}"
+ sep + ".box2{background:#EEEEEE;border-style:none none solid none;border-color:black;border-width:1px;padding:3px 0px 0px 0px}"
+ sep + ".box3{background:#FFFFFF;border:1px solid white;padding:0px 0px 0px 0px;cursor:hand}"
+ sep + ".boxA{height:12px;border:0px;padding:0px;text-align:center}"
+ sep + "</style>"
+ sep + "</head>"
+ sep + "<body bgcolor=\"#D4D0C8\" text=\"#000000\" scroll=\"no\" style=\"border:2px outset;margin-top:0px\">"
+ sep + "<span style=\"padding:0px 2px 0px 1px;z-index:2;position:relative;top:10px;left:3px;background:#D4D0C8\">日期/時間</span><span style=\"width:120px;cursor:default\" onmousedown=\"Drag()\"> </span>"
+ sep + "<table cellspacing=\"2\" cellpadding=\"2\" width=\"100%\" border=\"0\" style=\"border:2px groove;\">"
+ sep + " <tr><td height=\"5\"></td></tr>"
+ sep + " <tr>"
+ sep + " <td>"
+ sep + " <table cellspacing=\"2\" cellpadding=\"0\" width=\"100%\" border=\"0\">"
+ sep + " <tr>"
+ sep + " <td><input TABINDEX=\"-1\" id=\"myYear\" size=\"6\" maxlength=\"5\" onpropertychange=\"setCalendar()\"></td>"
+ sep + " <td><div><button TABINDEX=\"-1\" onclick=\"addYear()\" style=\"height:9px;width:16px\">^</button></div><div><button TABINDEX=\"-1\" onclick=\"decYear()\" style=\"height:9px;width:16px\">^</button></div></td>"
+ sep + " <td width=\"100%\">"
+ sep + " <select TABINDEX=\"-1\" id=\"myMonth\" onchange=\"setCalendar()\">"
+ sep + " <option value=\"1\">1月</option>"
+ sep + " <option value=\"2\">2月</option>"
+ sep + " <option value=\"3\">3月</option>"
+ sep + " <option value=\"4\">4月</option>"
+ sep + " <option value=\"5\">5月</option>"
+ sep + " <option value=\"6\">6月</option>"
+ sep + " <option value=\"7\">7月</option>"
+ sep + " <option value=\"8\">8月</option>"
+ sep + " <option value=\"9\">9月</option>"
+ sep + " <option value=\"10\">10月</option>"
+ sep + " <option value=\"11\">11月</option>"
+ sep + " <option value=\"12\">12月</option>"
+ sep + " </select>"
+ sep + " </td>"
+ sep + " <td><div align=\"center\" style=\"margin:0px;padding:0px;height:18px;width:62px;border:2px inset;background:white\"><input TABINDEX=\"-1\" class=\"boxA\" id=\"myHour\" size=\"1\" maxlength=\"2\" onfocus=\"setTimeSpan(this)\"><font style=\"font-size:8pt\">:</font><input TABINDEX=\"-1\" class=\"boxA\" id=\"myMinute\" size=\"1\" maxlength=\"2\" onfocus=\"setTimeSpan(this)\"><font style=\"font-size:8pt\">:</font><input TABINDEX=\"-1\" class=\"boxA\" id=\"mySecond\" size=\"1\" maxlength=\"2\" onfocus=\"setTimeSpan(this)\"></div></td>"
+ sep + " <td><div><button TABINDEX=\"-1\" onclick=\"addTime()\" style=\"height:9px;width:16px\">^</button></div><div><button TABINDEX=\"-1\" onclick=\"decTime()\" style=\"height:9px;width:16px\">^</button></div></td>"
+ sep + " </tr>"
+ sep + " <tr><td></td></tr>"
+ sep + " <tr>"
+ sep + " <td colspan=\"5\" align=\"center\">"
+ sep + " <table cellspacing=\"0\" cellpadding=\"0\" width=\"99%\" style=\"border:1px solid black\">"
+ sep + " <tr align=\"center\"><td class=\"box1\"><font color=red>日</font></td><td class=\"box1\">一</td><td class=\"box1\">二</td><td class=\"box1\">三</td><td class=\"box1\">四</td><td class=\"box1\">五</td><td class=\"box2\"><font color=green>六</font></td></tr>"
+ sep + " <tr height=\"2\" bgcolor=\"white\"><td colspan=\"7\"></td></tr>";
for(var i = 0;i < 6;i++) {
html += "<tr align=\"center\">";
for(var j = 0;j < 7;j++) {
html += "<td id=\"day_" + (i * 7 + j) + "\" class=\"box3\" onclick=\"setDay(this)\"> </td>";
}
html += "</tr>";
}
html +=
sep + " </table>"
+ sep + " </td>"
+ sep + " </tr>"
+ sep + " </table>"
+ sep + " </td>"
+ sep + " </tr>"
+ sep + "</table>"
+ sep + "<center><button style=\"position:relative;top:6px\" onclick=\"help_date_ok()\">確定</button> <button style=\"position:relative;top:6px\" onclick=\"help_date_cancel()\">取消</button></center>"
+ sep + "</body>"
+ sep + "</html>"
+ sep + script;
try {
help_frm.document.body.innerHTML = "";
var coll = help_frm.document.scripts;
for(var i=0;i<coll.length;i++) {
coll[i].text = "";
}
help_frm.document.write(html);
help_frm.resizeTo(WndWidth,WndHeight);
help_frm.moveTo(WndLeft,WndTop);
} catch(e) {}
}
function help_cancel(target,move) {
help_frm.moveTo(-2000,-2000);
var obj1 = document.getElementById(target);
var obj2 = document.getElementById(target.split("_")[0] + "_" + (parseInt(target.split("_")[1],10) + move));
if(obj2) obj2.focus();
else if(obj1) obj1.focus();
else KeyXp_setFocus();
}
//origin from validateEx.js
function isNaNEx(str) {
if(str == "") return true;
if(isNaN(str)) return true;
if(str.indexOf(".") != -1) return true;
return false;
}
function SearchEx(source,pattern,str) {
var index = pattern.indexOf(str);
if(index == -1) return "error";
return source.substring(index,index + str.length);
}
function validateDateEx(str,format) {
if(str.length != format.length) return false;
var year = 2000;
var month = 1;
var day = 1;
var hour = 0;
var minute = 0;
var second = 0;
if(format.indexOf("yyyy") != -1) {
if(isNaNEx(year = SearchEx(str,format,"yyyy"))) return false;
format = format.replace(/yyyy/,year);
}
if(format.indexOf("MM") != -1) {
if(isNaNEx(month = SearchEx(str,format,"MM"))) return false;
format = format.replace(/MM/,month);
}
if(format.indexOf("dd") != -1) {
if(isNaNEx(day = SearchEx(str,format,"dd"))) return false;
format = format.replace(/dd/,day);
}
if(format.indexOf("HH") != -1) {
if(isNaNEx(hour = SearchEx(str,format,"HH"))) return false;
if(parseInt(hour) < 0 || parseInt(hour) > 23) return false;
format = format.replace(/HH/,hour);
}
if(format.indexOf("mm") != -1) {
if(isNaNEx(minute = SearchEx(str,format,"mm"))) return false;
if(parseInt(minute) < 0 || parseInt(minute) > 59) return false;
format = format.replace(/mm/,minute);
}
if(format.indexOf("ss") != -1) {
if(isNaNEx(second = SearchEx(str,format,"ss"))) return false;
if(parseInt(second) < 0 || parseInt(second) > 59) return false;
format = format.replace(/ss/,second);
}
if(format != str) return false;
return isValidDate(year,month,day);
}
function isValidDate(year,month,day) {
month = parseInt(month,10);
day = parseInt(day,10);
if(month < 1 || month > 12) return false;
if(day < 1 || day > 31) return false;
if((month == 4 || month == 6 || month == 9 || month == 11) && (day == 31)) return false;
if (month == 2) {
var leap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day > 29 || (day == 29 && !leap)) return false;
}
return true;
}
//origin from time.js
function newDate(str,format) {
switch(format) {
case "yyyy-MM-dd":
var l = str.split("-")
return new Date(l[0],parseInt(l[1],10)-1,l[2]);
}
}
function year(date) {
var y = date.getFullYear();
return y;
}
function month(date) {
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -