LOGO OA教程 ERP教程 模切知识交流 PMS教程 CRM教程 开发文档 其他文档  
 
网站管理员

JavaScript时间日期控件

admin
2010年7月19日 9:16 本文热度 5655
[p]calendar.js(注:在.net环境下.js文件需存为utf-8格式)[/p] [p][br]/**//**[br]*本日历选择控件由tiannet根据前人经验完善而得。大部分代码来自meizz的日历控件。[br]*tiannet添加了时间选择功能、select,object标签隐藏功能,还有其它小功能。[br]*使用方法:[br]* (1)只选择日期 [br]* (2)选择日期和小时 [br]* (3)选择日期和小时及分钟 [br]*设置参数的方法[br]* (1)设置日期分隔符 setdatesplit(strsplit);默认为"-"[br]* (2)设置日期与时间之间的分隔符 setdatetimesplit(strsplit);默认为" "[br]* (3)设置时间分隔符 settimesplit(strsplit);默认为":"[br]* (4)设置(1),(2),(3)中的分隔符 setsplit(strdatesplit,strdatetimesplit,strtimesplit);[br]* (5)设置开始和结束年份 setyearperiod(intdatebeg,intdateend)[br]*说明:[br]* 默认返回的日期时间格式如同:2005-02-02 08:08[br]*/[br]//------------------ 样式定义 ---------------------------//[br]//功能按钮同样样式[br]var s_tiannet_turn_base = "height:16px;color:white;border:0 solid #cccccc;cursor:hand;background-color:#2650a6;";[br]//翻年、月等的按钮[br]var s_tiannet_turn = "width:28px;" + s_tiannet_turn_base;[br]//关闭、清空等按钮样式[br]var s_tiannet_turn2 = "width:22px;" + s_tiannet_turn_base;[br]//年选择下拉框[br]var s_tiannet_select = "width:64px;display:none;";[br]//月、时、分选择下拉框[br]var s_tiannet_select2 = "width:46px;display:none;";[br]//日期选择控件体的样式[br]var s_tiannet_body = "width:150;background-color:#2650a6;display:none;z-index:9998;position:absolute;" +[br]"border-left:1 solid #cccccc;border-top:1 solid #cccccc;border-right:1 solid #999999;border-bottom:1 solid #999999;";[br]//显示日的td的样式[br]var s_tiannet_day = "width:21px;height:20px;background-color:#d8f0fc;";[br]//字体样式[br]var s_tiannet_font = "color:#ffcc00;cursor:hand;";[br]//链接的样式[br]var s_tiannet_link = "text-decoration:none;color:#2650a6;";[br]//横线[br]var s_tiannet_line = "border-bottom:1 solid #6699cc";[br]//------------------ 变量定义 ---------------------------//[br]var tiannetyearst = 1950;//可选择的开始年份[br]var tiannetyearend = 2010;//可选择的结束年份[br]var tiannetdatenow = new date();[br]var tiannetyear = tiannetdatenow.getfullyear(); //定义年的变量的初始值[br]var tiannetmonth = tiannetdatenow.getmonth()+1; //定义月的变量的初始值[br]var tiannetday = tiannetdatenow.getdate();[br]var tiannethour = 8;//tiannetdatenow.gethours();[br]var tiannetminute = 0;//tiannetdatenow.getminutes();[br]var tiannetarrday=new array(42); //定义写日期的数组[br]var tiannetdatesplit = "-"; //日期的分隔符号[br]var tiannetdatetimesplit = " "; //日期与时间之间的分隔符[br]var tiannettimesplit = ":"; //时间的分隔符号[br]var tiannetoutobject; //接收日期时间的对象[br]var arrtiannethide = new array();//被强制隐藏的标签[br]var m_bolshowhour = false;//是否显示小时[br]var m_bolshowminute = false;//是否显示分钟[/p] [p]var m_amonhead = new array(12); //定义阳历中每个月的最大天数[br] m_amonhead[0] = 31; m_amonhead[1] = 28; m_amonhead[2] = 31; m_amonhead[3] = 30; m_amonhead[4] = 31; m_amonhead[5] = 30;[br] m_amonhead[6] = 31; m_amonhead[7] = 31; m_amonhead[8] = 30; m_amonhead[9] = 31; m_amonhead[10] = 30; m_amonhead[11] = 31;[br]// ---------------------- 用户可调用的函数 -----------------------------//[br]//用户主调函数-只选择日期[br]function setday(obj){[br]tiannetoutobject = obj;[br]//如果标签中有值,则将日期初始化为当前值[br]var strvalue = tiannettrim(tiannetoutobject.value);[br]if( strvalue != "" ){[br]tiannetinitdate(strvalue);[br]}[br]tiannetpopcalendar();[br]}[br]//用户主调函数-选择日期和小时[br]function setdayh(obj){[br]tiannetoutobject = obj;[br]m_bolshowhour = true;[br]//如果标签中有值,则将日期和小时初始化为当前值[br]var strvalue = tiannettrim(tiannetoutobject.value);[br]if( strvalue != "" ){[br]tiannetinitdate(strvalue.substring(0,10));[br]var hour = strvalue.substring(11,13);[br]if( hour < 10 ) tiannethour = hour.substring(1,2);[br]}[br]tiannetpopcalendar();[br]}[br]//用户主调函数-选择日期和小时及分钟[br]function setdayhm(obj){[br]tiannetoutobject = obj;[br]m_bolshowhour = true;[br]m_bolshowminute = true;[br]//如果标签中有值,则将日期和小时及分钟初始化为当前值[br]var strvalue = tiannettrim(tiannetoutobject.value);[br]if( strvalue != "" ){[br]tiannetinitdate(strvalue.substring(0,10));[br]var time = strvalue.substring(11,16);[br]var arr = time.split(tiannettimesplit);[br]tiannethour = arr[0];[br]tiannetminute = arr[1];[br]if( tiannethour < 10 ) tiannethour = tiannethour.substring(1,2);[br]if( tiannetminute < 10 ) tiannetminute = tiannetminute.substring(1,2);[br]}[br]tiannetpopcalendar();[br]}[br]//设置开始日期和结束日期[br]function setyearperiod(intdatebeg,intdateend){[br]tiannetyearst = intdatebeg;[br]tiannetyearend = intdateend;[br]}[br]//设置日期分隔符。默认为"-"[br]function setdatesplit(strdatesplit){[br]tiannetdatesplit = strdatesplit;[br]}[br]//设置日期与时间之间的分隔符。默认为" "[br]function setdatetimesplit(strdatetimesplit){[br]tiannetdatetimesplit = strdatetimesplit;[br]}[br]//设置时间分隔符。默认为":"[br]function settimesplit(strtimesplit){[br]tiannettimesplit = strtimesplit;[br]}[br]//设置分隔符[br]function setsplit(strdatesplit,strdatetimesplit,strtimesplit){[br]tiannetdatesplit(strdatesplit);[br]tiannetdatetimesplit(strdatetimesplit);[br]tiannettimesplit(strtimesplit);[br]}[br]//设置默认的日期。格式为:yyyy-mm-dd[br]function setdefaultdate(strdate){[br]tiannetyear = strdate.substring(0,4);[br]tiannetmonth = strdate.substring(5,7);[br]tiannetday = strdate.substring(8,10);[br]}[br]//设置默认的时间。格式为:hh24:mi[br]function setdefaulttime(strtime){[br]tiannethour = strtime.substring(0,2);[br]tiannetminute = strtime.substring(3,5);[br]}[br]// ---------------------- end 用户可调用的函数 -----------------------------//[br]//------------------ begin 页面显示部分 ---------------------------//[br]var weekname = new array("日","一","二","三","四","五","六");[br]document.write('
');[br]document.write('
');[br]document.write(' 年');[br]document.write('');[br]document.write('  月');[br]document.write('');[br]//document.write('
');[br]//document.write('
');[br]document.write(' 时');[br]document.write('');[br]document.write('  分');[br]document.write('');[br]document.write('
');[br]//输出一条横线[br]document.write('
');[br]document.write('
');[br]document.write('');[br]document.write(' ');[br]document.write('');[br]document.write('');[br]document.write('
');[br]//输出一条横线[br]document.write('
');[br]document.write('');[br]document.write(' ');[br]for(var i =0;i < weekname.length;i ++){[br]//输出星期[br]document.write('');[br]}[br]document.write(' ');[br]document.write('
' + weekname[i] + '
');[br]//输出天的选择[br]document.write('');[br]var n = 0;[br]for (var i=0;i<5;i++) { [br]document.write (' ');[br]for (var j=0;j<7;j++){[br]document.write('');[br]n ++;[br]}[br]document.write (' ');[br]}[br]document.write (' ');[br]document.write('');[br]document.write('');[br]document.write('');[br]document.write (' ');[br]document.write('
 
  清空'+[br] ' 关闭' +[br] ' 确定 ' +[br] '
');[br]document.write('
');[br]//------------------ end 页面显示部分 ---------------------------//[br]//------------------ 显示日期时间的span标签响应事件 ---------------------------//[br]//单击年份span标签响应[br]function spanyearcevent(){[br]hideelementsbyid(new array("seltianyear","tiannetmonthhead"),false);[br]if(m_bolshowhour) hideelementsbyid(new array("tiannethourhead"),false);[br]if(m_bolshowminute) hideelementsbyid(new array("tiannetminutehead"),false);[br]hideelementsbyid(new array("tiannetyearhead","seltianmonth","seltianhour","seltianminute"),true);[br]}[br]//单击月份span标签响应[br]function spanmonthcevent(){[br]hideelementsbyid(new array("seltianmonth","tiannetyearhead"),false);[br]if(m_bolshowhour) hideelementsbyid(new array("tiannethourhead"),false);[br]if(m_bolshowminute) hideelementsbyid(new array("tiannetminutehead"),false);[br]hideelementsbyid(new array("tiannetmonthhead","seltianyear","seltianhour","seltianminute"),true);[br]}[br]//单击小时span标签响应[br]function spanhourcevent(){[br]hideelementsbyid(new array("tiannetyearhead","tiannetmonthhead"),false);[br]if(m_bolshowhour) hideelementsbyid(new array("seltianhour"),false);[br]if(m_bolshowminute) hideelementsbyid(new array("tiannetminutehead"),false);[br]hideelementsbyid(new array("tiannethourhead","seltianyear","seltianmonth","seltianminute"),true);[br]}[br]//单击分钟span标签响应[br]function spanminutecevent(){[br]hideelementsbyid(new array("tiannetyearhead","tiannetmonthhead"),false);[br]if(m_bolshowhour) hideelementsbyid(new array("tiannethourhead"),false);[br]if(m_bolshowminute) hideelementsbyid(new array("seltianminute"),false);[br]hideelementsbyid(new array("tiannetminutehead","seltianyear","seltianmonth","seltianhour"),true);[br]}[br]//根据标签id隐藏或显示标签[br]function hideelementsbyid(arrid,bolhide){[br]var strdisplay = "";[br]if(bolhide) strdisplay = "none";[br]for(var i = 0;i < arrid.length;i ++){[br]var obj = document.getelementbyid(arrid[i]);[br]obj.style.display = strdisplay;[br]}[br]}[br]//------------------ end 显示日期时间的span标签响应事件 ---------------------------//[br]//判断某年是否为闰年[br]function ispinyear(year){[br]var bolret = false;[br]if (0==year%4&&((year%100!=0)||(year%400==0))) {[br]bolret = true;[br]}[br]return bolret;[br]}[br]//得到一个月的天数,闰年为29天[br]function getmonthcount(year,month){[br]var c=m_amonhead[month-1];[br]if((month==2)&&ispinyear(year)) c++;[br]return c;[br]}[br]//重新设置当前的日。主要是防止在翻年、翻月时,当前日大于当月的最大日[br]function setrealdaycount() {[br]if( tiannetday > getmonthcount(tiannetyear,tiannetmonth) ) {[br]//如果当前的日大于当月的最大日,则取当月最大日[br]tiannetday = getmonthcount(tiannetyear,tiannetmonth);[br]}[br]}[br]//在个位数前加零[br]function addzero(value){[br]if(value < 10 ){[br]value = "0" + value;[br]}[br]return value;[br]}[br]//取出空格[br]function tiannettrim(str) {[br]return str.replace(/(^\s*)|(\s*$)/g,"");[br]}[br]//为select创建一个option[br]function createoption(objselect,value,text){[br]var option = document.createelement("option");[br]option.value = value;[br]option.text = text;[br]objselect.options.add(option);[br]}[br]//往前翻 year[br]function tiannetprevyear() {[br]if(tiannetyear > 999 && tiannetyear <10000){tiannetyear--;}[br]else{alert("年份超出范围(1000-9999)!");}[br]tiannetsetday(tiannetyear,tiannetmonth);[br]//如果年份小于允许的最小年份,则创建对应的option[br]if( tiannetyear < tiannetyearst ) {[br]tiannetyearst = tiannetyear;[br]createoption(document.all.seltianyear,tiannetyear,tiannetyear + "年");[br]}[br]checkselect(document.all.seltianyear,tiannetyear);[br]tiannetwritehead();[br]}[br]//往后翻 year[br]function tiannetnextyear() {[br]if(tiannetyear > 999 && tiannetyear <10000){tiannetyear++;}[br]else{alert("年份超出范围(1000-9999)!");return;}[br]tiannetsetday(tiannetyear,tiannetmonth);[br]//如果年份超过允许的最大年份,则创建对应的option[br]if( tiannetyear > tiannetyearend ) {[br]tiannetyearend = tiannetyear;[br]createoption(document.all.seltianyear,tiannetyear,tiannetyear + "年");[br]}[br]checkselect(document.all.seltianyear,tiannetyear);[br]tiannetwritehead();[br]}[br]//选择今天[br]function tiannettoday() {[br]tiannetyear = tiannetdatenow.getfullyear();[br]tiannetmonth = tiannetdatenow.getmonth()+1;[br]tiannetday = tiannetdatenow.getdate();[br]tiannetsetvalue(true);[br]//tiannetsetday(tiannetyear,tiannetmonth);[br]//selectobject();[br]}[br]//往前翻月份[br]function tiannetprevmonth() {[br]if(tiannetmonth>1){tiannetmonth--}else{tiannetyear--;tiannetmonth=12;}[br]tiannetsetday(tiannetyear,tiannetmonth);[br]checksele

该文章在 2010/7/19 9:16:07 编辑过
关键字查询
相关文章
正在查询...
点晴ERP是一款针对中小制造业的专业生产管理软件系统,系统成熟度和易用性得到了国内大量中小企业的青睐。
点晴PMS码头管理系统主要针对港口码头集装箱与散货日常运作、调度、堆场、车队、财务费用、相关报表等业务管理,结合码头的业务特点,围绕调度、堆场作业而开发的。集技术的先进性、管理的有效性于一体,是物流码头及其他港口类企业的高效ERP管理信息系统。
点晴WMS仓储管理系统提供了货物产品管理,销售管理,采购管理,仓储管理,仓库管理,保质期管理,货位管理,库位管理,生产管理,WMS管理系统,标签打印,条形码,二维码管理,批号管理软件。
点晴免费OA是一款软件和通用服务都免费,不限功能、不限时间、不限用户的免费OA协同办公管理系统。
Copyright 2010-2024 ClickSun All Rights Reserved