📄 bsdate.js
字号:
var BSPopup = window.createPopup();
BSDate.cl_resClickLater = '请在页面显示完了之后,再点击。';
BSDate.cl_resDateDrop = '▼';
BSDate.cl_resDateTitle = '选择日期';
BSDate.cl_resDateUp = '▲';
BSDate.cl_resDay = '日';
BSDate.cl_resMonth = '月';
BSDate.cl_resMonth1 = '一月';
BSDate.cl_resMonth10 = '十月';
BSDate.cl_resMonth11 = '十一月';
BSDate.cl_resMonth12 = '十二月';
BSDate.cl_resMonth2 = '二月';
BSDate.cl_resMonth3 = '三月';
BSDate.cl_resMonth4 = '四月';
BSDate.cl_resMonth5 = '五月';
BSDate.cl_resMonth6 = '六月';
BSDate.cl_resMonth7 = '七月';
BSDate.cl_resMonth8 = '八月';
BSDate.cl_resMonth9 = '九月';
BSDate.cl_resMonthNext = '下月';
BSDate.cl_resMonthNextBtn = '》';
BSDate.cl_resMonthPrev = '上月';
BSDate.cl_resMonthPrevBtn = '《';
BSDate.cl_resWeek1 = '一';
BSDate.cl_resWeek2 = '二';
BSDate.cl_resWeek3 = '三';
BSDate.cl_resWeek4 = '四';
BSDate.cl_resWeek5 = '五';
BSDate.cl_resWeek6 = '六';
BSDate.cl_resWeek7 = '日';
BSDate.cl_resYear = '年';
BSDate.dateHTML = "";
BSDate.m_iDatePickerCount=0;
BSDate.cl_dpMaxYear=2150;
BSDate.cl_dpMaxMonth=11;
BSDate.cl_dpMaxDay=31;
BSDate.cl_dpMinYear=1901;
BSDate.cl_dpMinMonth=0;
BSDate.cl_dpMinDay=1;
BSPopup_style_title = "FONT-WEIGHT: normal;FONT-SIZE: 9pt;COLOR: #fffacd;background-COLOR: #00008b;";
BSPopup_style_frameinput = "height:18px;width:15px;BORDER: black 0px solid;FONT-WEIGHT: normal;FONT-SIZE: 9pt;black: blue;LINE-HEIGHT: normal;FONT-STYLE: normal;background-COLOR: transparent;Text-ALIGN: right;FONT-VARIANT: normal;";
BSPopup_style_framebtn = "BORDER-RIGHT: black 1px solid;border-TOP: white 1px solid;FONT-WEIGHT: normal;FONT-SIZE: 9pt;border-LEFT: white 1px solid;width: 16px;COLOR: blue;LINE-HEIGHT: normal;border-BOTTOM: black 1px solid;FONT-STYLE: normal;background-COLOR: silver;FONT-VARIANT: normal;";
BSPopup_style_framebtnOK = "BORDER-RIGHT: black 1px solid;border-TOP: white 1px solid;FONT-WEIGHT: normal;FONT-SIZE: 9pt;border-LEFT: white 1px solid;width: 30px;COLOR: blue;LINE-HEIGHT: normal;border-BOTTOM: black 1px solid;FONT-STYLE: normal;background-COLOR: silver;FONT-VARIANT: normal;";
BSPopup_style_framebtnOK2 = "background-COLOR: silver;BORDER-RIGHT: black 1px solid;border-TOP: white 1px solid;width: 16px;border-LEFT: white 1px solid;border-BOTTOM: black 1px solid;height: 8px;font-family:Webdings;font-size: 7px;line-height: 2px;padding-left: 2px;cursor: default;";
BSPopup_style_weekname = "FONT-WEIGHT: normal;COLOR: #00008b;LINE-HEIGHT: normal;BORDER-BOTTOM: black 1px solid;FONT-SIZE: 9pt;FONT-STYLE: normal;TEXT-ALIGN: center;FONT-VARIANT: normal;";
BSPopup_style_table = "BORDER-TOP: lightgrey 1px solid;BORDER-LEFT: lightgrey 1px solid;CURSOR: default;BORDER-right: black 1px solid;BORDER-BOTTOM: black 1px solid;POSITION: absolute;BACKGROUND-COLOR: #ffffff;";
BSPopup_style_DPCellOther = "FONT-WEIGHT: normal;FONT-SIZE: 9pt;CURSOR: hand;COLOR: silver;LINE-HEIGHT: normal;FONT-STYLE: normal;TEXT-ALIGN: center;FONT-VARIANT: normal;";
BSPopup_style_DPCell = "FONT-WEIGHT: normal;FONT-SIZE: 9pt;CURSOR: hand;COLOR: #00008b;LINE-HEIGHT: normal;FONT-STYLE: normal;TEXT-ALIGN: center;FONT-VARIANT: normal;";
BSPopup_style_DPCellSelect = "FONT-WEIGHT: normal;FONT-SIZE: 9pt;CURSOR: hand;COLOR: #000000;LINE-HEIGHT: normal;FONT-STYLE: normal;TEXT-ALIGN: center;FONT-VARIANT: normal;BACKGROUND-COLOR: #ffa07a;";
//效验
function KeyFilter(type)
{
var berr=false;
switch(type)
{
case 'date':
if (!(event.keyCode == 45 || event.keyCode == 47 || (event.keyCode>=48 && event.keyCode<=57)))
berr=true;
break;
case 'number':
if (!(event.keyCode>=48 && event.keyCode<=57))
berr=true;
break;
case 'cy':
if (!(event.keyCode == 46 || (event.keyCode>=48 && event.keyCode<=57)))
berr=true;
break;
case 'long':
if (!(event.keyCode == 45 || (event.keyCode>=48 && event.keyCode<=57)))
berr=true;
break;
case 'double':
if (!(event.keyCode == 45 || event.keyCode == 46 || (event.keyCode>=48 && event.keyCode<=57)))
berr=true;
break;
default:
if (event.keyCode == 35 || event.keyCode == 37 || event.keyCode==38)
berr=true;
}
return !berr;
}
//日期比较
function dateCompare(thisDt, dtCompare){
var hr = -1;
if(thisDt && dtCompare)
{
if(thisDt.getFullYear()>dtCompare.getFullYear())
hr=1;
else if(thisDt.getFullYear()<dtCompare.getFullYear())
hr=-1;
else if(thisDt.getMonth()>dtCompare.getMonth())
hr=1;
else if(thisDt.getMonth()<dtCompare.getMonth())
hr=-1;
else if(thisDt.getDate()>dtCompare.getDate())
hr=1;
else if(thisDt.getDate()<dtCompare.getDate())
hr=-1;
}
return hr;
}
//日期格式化
function dateFormat(dt, sFormat){
if(sFormat==null || typeof(sFormat)!="string")
sFormat="";
sFormat=sFormat.replace(/yyyy/ig,dt.getFullYear());
var y=""+dt.getYear();
if(y.length>2)
{
y=y.substring(y.length-2,y.length);
}
sFormat=sFormat.replace(/yy/ig,y);
sFormat=sFormat.replace(/mm/ig,dt.getMonth()+1);
sFormat=sFormat.replace(/dd/ig,dt.getDate());
sFormat=sFormat.replace(/hh24/ig,dt.getHours());
sFormat=sFormat.replace(/mi/ig,dt.getMinutes());
sFormat=sFormat.replace(/ss/ig,0);
return sFormat;
}
//将yyyy-mm-dd hh24:mi:ss形式的字符串转换为日期时间对象
function StringToDate(inStr){
var dt = new Date();
if (inStr != null && inStr != ""){
var dList = null;
var tList = null;
if (inStr.indexOf(' ') < 1){
dList = inStr.split('-');
}
else{
dList = (inStr.substring(0, inStr.indexOf(' '))).split('-');
tList = (inStr.substring(inStr.indexOf(' ')+1, inStr.length)).split(':');
}
dt.setYear(dList[0]);
dt.setMonth(dList[1]-1);
dt.setDate(dList[2]);
if (tList != null){
dt.setHours(tList[0]);
dt.setMinutes(tList[1]);
}
else{
dt.setHours(0);
dt.setMinutes(0);
}
}
return dt;
}
function BSDate(name, elmName, readonly, showTime){
this.name = name || "bsDate";//日期对象实例
this.readonly = readonly || false;//只读标志
this.elmName = elmName || "bsDateObj";//装载日期控件的文本框名称
this.showTime;//显示时间,false:不显示;true:显示,缺省为true;
if (showTime == null){
this.showTime = true;
}
else{
this.showTime = showTime;
}
this.bsdate = new Date();
//得到日期名称
this.getMonthName = function(lMonth){
var mnArr=new Array(BSDate.cl_resMonth1,BSDate.cl_resMonth2,BSDate.cl_resMonth3,BSDate.cl_resMonth4,BSDate.cl_resMonth5,BSDate.cl_resMonth6,
BSDate.cl_resMonth7,BSDate.cl_resMonth8,BSDate.cl_resMonth9,BSDate.cl_resMonth10,BSDate.cl_resMonth11,BSDate.cl_resMonth12);
return mnArr[lMonth];
}
//得到日期对象
this.getDateObj = function (){
return this.bsdate;
}
//得到日期字符串
this.getDateStr = function (){
return document.getElementById(this.elmName).value;
}
//初始化或修改日期时间
this.updateDateTime = function(dt, lYear, lMonth, lDay, lHours, lMins){
if (this.readonly){
return;
}
if (dt == null){
lYear=parseInt(lYear,10);
lMonth=parseInt(lMonth,10);
lDay=parseInt(lDay,10);
lHours=parseInt(lHours,10);
lMins=parseInt(lMins,10);
if(!(isNaN(lYear) || isNaN(lMonth) || isNaN(lDay) || isNaN(lHours) || isNaN(lMins))){
this.bsdate.setYear(lYear);
this.bsdate.setMonth(lMonth-1);
this.bsdate.setDate(lDay);
this.bsdate.setHours(lHours);
this.bsdate.setMinutes(lMins);
}
}
else{
this.bsdate = dt;
}
this.setInputDate();
}
//初始化或修改日期
this.updateDate = function(lYear, lMonth, lDay){
if (this.readonly){
return;
}
lYear=parseInt(lYear,10);
lMonth=parseInt(lMonth,10);
lDay=parseInt(lDay,10);
if(!(isNaN(lYear) || isNaN(lMonth) || isNaN(lDay))){
this.bsdate.setYear(lYear);
this.bsdate.setMonth(lMonth-1);
this.bsdate.setDate(lDay);
}
this.setInputDate();
}
//初始化或修改时间
this.updateTime = function(lHours, lMins){
if (this.readonly){
return;
}
lHours=parseInt(lHours,10);
lMins=parseInt(lMins,10);
if(!(isNaN(lHours) || isNaN(lMins))){
this.bsdate.setHours(lHours);
this.bsdate.setMinutes(lMins);
}
this.setInputDate();
}
//设置只读标志
this.setReadonly = function(readonly){
this.readonly = readonly || false;
if (document.getElementById(this.elmName) != null){
var col = "black";
if (this.readonly){
col = "silver";
}
document.getElementById(this.name+"_input_year").readOnly = this.readonly;
document.getElementById(this.name+"_input_month").readOnly = this.readonly;
document.getElementById(this.name+"_input_day").readOnly = this.readonly;
document.getElementById(this.name+"_input_hour").readOnly = this.readonly;
document.getElementById(this.name+"_input_min").readOnly = this.readonly;
document.getElementById(this.name+"_btn").style.color = col;
}
}
//设置时间显示标志
this.setTimeShow = function(showTime){
this.showTime = showTime || false;
if (document.getElementById(this.elmName) != null){
var col = "none";
if (this.showTime){
col = "";
}
var stformt="yyyy-mm-dd hh24:mi:ss";
if (!this.showTime){
stformt = "yyyy-mm-dd";
}
document.getElementById(this.name+"_input_hour").style.display = col;
document.getElementById(this.name+"_input_mh").style.display = col;
document.getElementById(this.name+"_input_min").style.display = col;
document.getElementById(this.elmName).value = dateFormat(this.bsdate, stformt);
}
}
this.setDateHTML = function(){
this.setInputDate();
var dt = new Date(this.bsdate.getFullYear(),this.bsdate.getMonth(),1);
var tempDt=new Date(this.bsdate.getFullYear(),this.bsdate.getMonth(),1-dt.getDay());
BSDate.dateHTML = "<TABLE style=\""+BSPopup_style_table+"\" id=\"dpDropDownTable\" align=\"center\" CELLSPACING=\"0\" border=0>";
BSDate.dateHTML += "<TR style=\""+BSPopup_style_title+"\" onselectstart=\"event.cancelBubble=true;window.event.returnValue=false;\">";
BSDate.dateHTML += "<TD align=\"center\"><span style=\""+BSPopup_style_framebtn+"\" onclick=\"parent."+this.name+".changeMonth(event, true);\" title=\""+BSDate.cl_resMonthPrev+"\">"+BSDate.cl_resMonthPrevBtn+"<span></TD>";
BSDate.dateHTML += "<TD align=\"center\" colspan=\"5\">"+this.getMonthName(this.bsdate.getMonth())+" "+this.bsdate.getFullYear()+"</TD>";
BSDate.dateHTML += "<TD align=\"center\"><span style=\""+BSPopup_style_framebtn+"\" onclick=\"parent."+this.name+".changeMonth(event, false);\" title=\""+BSDate.cl_resMonthNext+"\">"+BSDate.cl_resMonthNextBtn+"<span></TD>";
BSDate.dateHTML += "</TR>";
BSDate.dateHTML += "<TR onselectstart=\"event.cancelBubble=true;window.event.returnValue=false;\">";
BSDate.dateHTML += "<TD align=\"center\" style=\""+BSPopup_style_weekname+"\"> "+BSDate.cl_resWeek7+" </TD>";
BSDate.dateHTML += "<TD align=\"center\" style=\""+BSPopup_style_weekname+"\"> "+BSDate.cl_resWeek1+" </TD>";
BSDate.dateHTML += "<TD align=\"center\" style=\""+BSPopup_style_weekname+"\"> "+BSDate.cl_resWeek2+" </TD>";
BSDate.dateHTML += "<TD align=\"center\" style=\""+BSPopup_style_weekname+"\"> "+BSDate.cl_resWeek3+" </TD>";
BSDate.dateHTML += "<TD align=\"center\" style=\""+BSPopup_style_weekname+"\"> "+BSDate.cl_resWeek4+" </TD>";
BSDate.dateHTML += "<TD align=\"center\" style=\""+BSPopup_style_weekname+"\"> "+BSDate.cl_resWeek5+" </TD>";
BSDate.dateHTML += "<TD align=\"center\" style=\""+BSPopup_style_weekname+"\"> "+BSDate.cl_resWeek6+" </TD>";
BSDate.dateHTML += "</TR>";
//显示日期
var day=tempDt.getDate();
for(var i=2; i<8; i++){
BSDate.dateHTML += "<TR onselectstart=\"event.cancelBubble=true;window.event.returnValue=false;\">";
for(var j=0; j<7; j++){
BSDate.dateHTML += "<TD ";
if(tempDt.getMonth()!=this.bsdate.getMonth()){
BSDate.dateHTML += "style=\""+BSPopup_style_DPCellOther+"\" ";
}
else if (tempDt.getDate()!=this.bsdate.getDate()){
BSDate.dateHTML += "style=\""+BSPopup_style_DPCell+"\" ";
}
else{
BSDate.dateHTML += "style=\""+BSPopup_style_DPCellSelect+"\" ";
}
BSDate.dateHTML += (" onclick=\"parent."+this.name+".changeDay(event, "+tempDt.getFullYear()+", "+tempDt.getMonth()+", "+day+");\" ");
BSDate.dateHTML += (" ondblclick=\"parent.BSPopup.hide();\"");
BSDate.dateHTML += ">"+day+"</TD>";
tempDt.setDate(day+1);
day=tempDt.getDate();
}
BSDate.dateHTML += "</TR>";
}
BSDate.dateHTML += "<TR><TD colspan=\"7\" style=\"BORDER-TOP: black 1px solid;width:100%;height:20px;\" valign=\"top\">";
BSDate.dateHTML += "<TABLE style=\"width:100%;height:25px;\">";
BSDate.dateHTML += "<TR>";
if (this.showTime){
BSDate.dateHTML += "<TD style=\"width:15;height:20px;\"><span style=\""+BSPopup_style_frameinput+"\">"+this.bsdate.getHours()+"</span></TD>";
BSDate.dateHTML += "<TD style=\"width:16px;FONT-SIZE: 9pt;FONT-WEIGHT: normal;\" valign=\"top\">";
BSDate.dateHTML += "<input type=\"button\" onFocus=\"this.blur();\" style=\""+BSPopup_style_framebtnOK2+"\" onclick=\"parent."+this.name+".changeHour(event, 1)\" id=\"BSPopup_H_A\" value=\"5\"/><br/>";
BSDate.dateHTML += "<input type=\"button\" onFocus=\"this.blur();\" style=\""+BSPopup_style_framebtnOK2+"\" onclick=\"parent."+this.name+".changeHour(event, -1)\" id=\"BSPopup_H_D\" value=\"6\"/>";
BSDate.dateHTML += "<TD style=\"width:12px;FONT-SIZE: 9pt;FONT-WEIGHT: normal;\">时</TD>";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -