酒店入住离店js日历代码
轻量级的原生js日历插件calendar.js使用指南
轻量级的原⽣js⽇历插件calendar.js使⽤指南使⽤说明:需要引⼊插件calendar.js/calendar.min.js须要引⼊calendar.css 样式表,可以⾃定义⾃⼰想要的⽪肤本⽇历插件⽀持cmd模块化如下调⽤:复制代码代码如下:xvDate({'targetId':'date1',//时间写⼊对象的id'triggerId':['date1','dateBtn1'],//触发事件的对象id'alignId':'datesWrap1',//⽇历对齐对象'format':'-',//时间格式默认'YYYY-MM-DD HH:MM:SS''min':'2014-09-20 10:00:00',//最⼤时间'max':'2014-10-30 10:00:00'//最⼩时间});参数说明:targetId :⽇期写⼊对象的id,不能为空triggerId :触发事件的对象id,如果不设置则默认为targetIdalignId :⽇历盒⼦的对齐基准,如果不设置则默认为targetIdhms :时分秒是否开启,默认值为'on'则表⽰开启时分秒(2014-09-20 10:00:00),'off'则表⽰关闭时分秒模式(2014-09-20) format :为⽇期格式默认值为'-' (2014-09-20),'/'则表⽰(2014/09/20)min :最⼩时间限制,min 的时间格式和前⾯的时间格式保持⼀直max :最⼤时间限制,max 的时间格式和前⾯的时间格式保持⼀直zIndex :最⼤时间限制,⽇历盒⼦的层级,默认9999如果需要使⽤模块化在需要依赖的模块⽤引⼊即可如:复制代码代码如下:define('mod1',[],function(require, exports, module){var xvDate = require("xvDate");})以上所述就是本⽂的全部内容了,希望⼤家能够喜欢。
js获取日期:昨天今天和明天、后天
js获取⽇期:昨天今天和明天、后天复制代码代码如下:<html><head><meta http-equiv="Content-Type" content="textml; charset=utf-8"><title>js获取⽇期:前天、昨天、今天、明天、后天 - </title></head><body><script language="JavaScript" type="text/javascript">function GetDateStr(AddDayCount) {var dd = new Date();dd.setDate(dd.getDate()+AddDayCount);//获取AddDayCount天后的⽇期var y = dd.getFullYear();var m = dd.getMonth()+1;//获取当前⽉份的⽇期var d = dd.getDate();return y+"-"+m+"-"+d;}document.write("前天:"+GetDateStr(-2));document.write("<br />昨天:"+GetDateStr(-1));document.write("<br />今天:"+GetDateStr(0));document.write("<br />明天:"+GetDateStr(1));document.write("<br />后天:"+GetDateStr(2));document.write("<br />⼤后天:"+GetDateStr(3));</script></body><ml>其中有⼀种⽅法是:Date.parse(dateVal),此函数功能强⼤,但是有个致命的缺点,那就是不⽀持我们常⽤的“年-⽉-⽇”格式,短⽇期可以使⽤“/”或“-”作为⽇期分隔符,但是必须⽤⽉/⽇/年的格式来表⽰,例如"7/20/96"。
js实现日历
js实现⽇历这周写⾃⼰的项⽬发现⼜⽤到⽇历了,加之⾃⼰毕业之后的第⼀个⼯作中遇到的任务也是需要写个⽇历(组员写了,我就不⽤写了)今天就来好好折腾⼀下⽇历是怎么写的。
⾸先,我们看看 windows 的⽇历。
发现总共有这么⼏个元素。
先实现试试。
1.年份的选择、⽉份的选择2.周⼀ ~ 周⽇(周⽇ ~ 周六)3.⽇历格⼦ 6*7 = 42从数据的⾓度来分析⽇历的实现是⽐较简单的1.我们需要显⽰⼀个当前时间的结构 - new Date()2.我们需要显⽰当⽉的信息 - [星期(周⼀~周⽇),⽇期(1-[28,29,30,31])]其中我们只要知道了每个⽉的 1⽇是星期⼏,就能很容易地摆放后⾯的⽇⼦(万事开头难)。
我们最多需要 6 ⾏来显⽰我们的⽇期,因为要第⼀排如果只包含本⽉的⼀天 6(上个⽉的) + (1 + 4*7),这样就五⾏了,当⽉天数若⼤于 29,就显⽰不下了确定了 6 ⾏之后,我们发现我们可能需要获取上个⽉,和下个⽉多出来的⼏天的摆放位置。
不同年份的不同⽉的 2⽉份,我们知道它的⽇期是不同的,所以我们还需要判断平年还是闰年。
3.显⽰上个⽉,下个⽉的切换。
我们发现需要有个函数来帮我们更新⽇历。
分析完之后,让我们跟着新增/修改⼀些代码。
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>Document</title><style>.week-item {display: inline-block;width: 80px;height: 40px;line-height: 40px;border: 1px solid sandybrown;text-align: center;}.date-item {display: inline-block;width: 80px;height: 40px;line-height: 40px;border: 1px solid beige;text-align: center;}</style></head><body><div class="wrapper"><div class="year-line"><button id="preMonth" class="year-prev">上⼀⽉</button><button id="nowYear" class="year-now"></button><button id="nowMonth"></button><button id="nowDate"></button><button id="nextMonth" class="year-next">下⼀⽉</button></div><div id="weekLine" class="week-line"></div><div id="dateWrap" class="date-wrap"></div></div></body><script>// ⼯具⽅法 - start// 1.为了获得每个⽉的⽇期有多少,我们需要判断平年闰年[四年⼀闰,百年不闰,四百年再闰]const isLeapYear = (year) => {return (year % 400 === 0) || (year % 100 !== 0 && year % 4 === 0);};// 2.获得每个⽉的⽇期有多少,注意 month - [0-11]const getMonthCount = (year, month) => {let arr = [31, null, 31, 30,31, 30, 31, 31,30, 31, 30, 31];let count = arr[month] || (isLeapYear(year) ? 29 : 28);return Array.from(new Array(count), (item, value) => value + 1);};// 3.获得某年某⽉的 1号是星期⼏,这⾥要注意的是 JS 的 API-getDay() 是从 [⽇-六](0-6),返回 numberconst getWeekday = (year, month) => {let date = new Date(year, month, 1);return date.getDay();};// 4.获得上个⽉的天数const getPreMonthCount = (year, month) => {if (month === 0) {return getMonthCount(year - 1, 11);} else {return getMonthCount(year, month - 1);}};// 5.获得下个⽉的天数const getNextMonthCount = (year, month) => {if (month === 11) {return getMonthCount(year + 1, 0);} else {return getMonthCount(year, month + 1);}};// ⼯具⽅法 - endlet weekStr = '⽇⼀⼆三四五六';weekArr = weekStr.split('').map(item => '星期' + item);// 插⼊星期 domlet weekDomStr = '';let oFragWeek = document.createDocumentFragment();weekArr.forEach(item => {let oSpan = document.createElement('span');let oText = document.createTextNode(item);oSpan.appendChild(oText);oSpan.classList.add('week-item');oFragWeek.appendChild(oSpan);});let weekWrap = document.getElementById('weekLine');weekWrap.appendChild(oFragWeek);// 这⾥获得我们第⼀次的数据数组const updateCalendar = (year, month, day) => {if (typeof year === 'undefined' && typeof month === 'undefined' && typeof day === 'undefined') {let nowDate = new Date();year = nowDate.getFullYear();month = nowDate.getMonth();day = nowDate.getDate();}// 更新⼀下顶部的年⽉显⽰document.getElementById('nowYear').innerHTML = year;document.getElementById('nowMonth').innerHTML = month + 1;document.getElementById('nowDate').innerHTML = day;// ⽣成⽇历数据,上个⽉剩下的的 x 天 + 当⽉的 28(平年的2⽉)或者29(闰年的2⽉)或者30或者31天 + 下个⽉的 y 天 = 42 let res = [];let currentMonth = getMonthCount(year, month);let preMonth = getPreMonthCount(year, month);let nextMonth = getNextMonthCount(year, month);let whereMonday = getWeekday(year, month);if (whereMonday === 0) {whereMonday = 7}// 感谢⽹友 luoyiming 的测试(哈哈!谢谢!):这⾥当 whereMonday 为 0 的时候会截取上⽉的所有数据let preArr = preMonth.slice(-1 * whereMonday)let nextArr = nextMonth.slice(0, 42 - currentMonth.length - whereMonday);res = [].concat(preArr, currentMonth, nextArr);// 上⾯经过我本⼈的测试是没有什么问题,接下来就是更新 dom 的信息的问题let hadDom = document.getElementsByClassName('date-item');if (hadDom && hadDom.length) {let domArr = document.getElementsByClassName('date-item');for (let i = 0; i < domArr.length; i++) {domArr[i].innerHTML = res.shift();}} else {// 如果之前没有结构的话let str = '';for (let i = 0; i < 6; i++) {str += '<div class="date-line">';for (let j = 0; j < 7; j++) {str += `<span class='date-item'>${res.shift()}</span>`;if (j === 6) {str += '</div>';}}}document.getElementById('dateWrap').innerHTML = str;}};updateCalendar();// 添加上⼀⽉,下⼀⽉事件let oPreButton = document.getElementById('preMonth');let oNextButton = document.getElementById('nextMonth');oPreButton.addEventListener('click', function () {let currentYear = +document.getElementById('nowYear').textContent;let currentMonth = +document.getElementById('nowMonth').textContent - 1;let currentDate = +document.getElementById('nowDate').textContent;if (currentMonth === 0) {updateCalendar(currentYear - 1, 11, currentDate);} else {updateCalendar(currentYear, currentMonth - 1, currentDate);}});oNextButton.addEventListener('click', function () {let currentYear = +document.getElementById('nowYear').textContent;let currentMonth = +document.getElementById('nowMonth').textContent - 1;let currentDate = +document.getElementById('nowDate').textContent;if (currentMonth === 11) {updateCalendar(currentYear + 1, 0, currentDate);} else {updateCalendar(currentYear, currentMonth + 1, currentDate);}});</script></html>发现⽤ dom 直接操作⽽不是通过 mvvm 框架实现确实还是⽐较蛋疼的,以下是这次实现的效果。
酒店客房管理系统VB
一、系统概述(一)选题背景近年来,随着我国酒店业的迅猛发展,行业内的竞争日趋激烈,同时对酒店的管理也提出了更高的要求。
随着计算机技术的发展和互联网时代的到来,人们已经进入了信息时代,现代化节奏越来越快,市场竞争日趋激烈。
传统的人工管理模式已经远远不能满足有效、快捷地处理经营中产生的大量信息数据的需要,从而使得企业决策层无法及时、准确地掌握一线资料,继而影响对市场进行正确地分析和预测。
酒店业如何面向市场,如何提高现代化管理水平,如何面临与时代接轨的问题,如何增强酒店的竞争能力提高酒店的管理水平——先进的酒店管理信息系统己成为现代酒店经营者的必然选择。
将计算机技术应用酒店管理信息系统,不仅可以提高酒店管理的效率、提升服务质量,而且还可以实现降低运营成本和资源共享,能够全面了解酒店的营业情况,更好地进行市场分析、决策研究,提升酒店的经济效益和综合实力。
在当今信息时代,管理科学与信息技术相互影响,相互促进,联系己十分紧密。
而融合了管理科学、信息技术以及系统工程学的管理信息系统作为现代化商业管理的重要手段,对企业的生存和发展起着决定性的作用。
一个成功的酒店,不仅要提高服务水平和服务质量,从而提高客户占有率和回头率,还要有好的工作效率,并控制成本。
在信息时代,更重要的是还必须要有一个完善的管理信息系统,便于方便客人和更好地管理酒店。
酒店管理系统发展概况管理信息系统(Management Information System简称MIS)是信息科学的一个分支,是由人和计算机组成的能进行信息的收集、传递、储存、加工、维护和使用的系统。
酒店管理系统是MIS中的一个重要分支,它实现的是计算机管理系统在酒店宾馆中的具体应用。
它最早是于70年代初在国外开始发展起来的,经过十几年的发展,到了80年代,国外的宾馆管理系统的整个模式已基本定型,如HIS,ECCO,Lodgistix,FIDELIO,CLS等,技术较成熟,功能也较为齐全。
宾馆客房系统代码
宾馆客房系统代码第一页面中标签控件属性如下: Object Label1: Tlabel Left=57 Top=78Width=36Height=12Caption='房间号'Object Label1: Tlabel Left=57Top=110Width=48Height=12Caption='客户姓名'Object Label1: Tlabel Left=57Top=142Width=48Height=12Caption='身份证号码'Object Label1: Tlabel Left=57Top=174Width=48Height=12Caption='入住时间'Object Label1: Tlabel Left=57Top=214Width=48Height=12Caption='入住理由'Object Label1: Tlabel Left=312 Top=78Width=24Height=12Caption='房价'Object Label1: TlabelLeft=312Top=110Width=48Height=12Caption='住宿天数'Object Label1: TlabelLeft=312Top=142Width=48Height=12Caption='值班人员'Object Label1: TlabelLeft=312Top=174Width=48Height=12Caption='电话号码'Object Label1: TlabelLeft=312Top=214Width=48Height=12Caption='结算费用'Object Label1: TlabelLeft=224Top=24Width=120Height=20Caption='顾客入住登记'Font.Height=-20 ='宋体' 第一页面中数据编辑类控件属性如下: Object DBEdit1: TDBEditLeft=129Top=79Width=121Height=20DataField='房间号'DataSource=Datasource1Taborder=0Object DBEdit1: TDBEdit Left=129Top=111Width=121Height=20DataField='客户姓名' DataSource=Datasource1 Taborder=1Object DBEdit1: TDBEdit Left=129Top=143Width=121Height=20DataField='身份证号码' DataSource=Datasource1 Taborder=2Object DBEdit1: TDBEdit Left=129Top=175Width=121Height=20DataField='入住时间' DataSource=Datasource1 Taborder=3Object DBEdit1: TDBEdit Left=129Top=207Width=121Height=20DataField='入住理由' DataSource=Datasource1 Taborder=4Object DBEdit1: TDBEdit Left=129Top=79Width=121Height=20DataField='房价' DataSource=Datasource1 Taborder=5Object DBEdit1: TDBEdit Left=382Top=111Width=121Height=20DataField='入住天数' DataSource=Datasource1 Taborder=6Object DBEdit1: TDBEdit Left=382Top=143Width=121Height=20DataField='值班人员' DataSource=Datasource1 Taborder=7Object DBEdit1: TDBEdit Left=382Top=175Width=121Height=20DataField='电话号码' DataSource=Datasource1 Taborder=8Object DBEdit1: TDBEdit Left=382Top=207Width=121Height=20DataField='结算费用' DataSource=Datasource1 Taborder=9第一页面中数据连接类控件属性如下:Object Table1: TtableActive=TureTableName=宾馆住宿系统.dbLeft=488Top=64Object DataSource1: TdataSourceDataSet=Table1Object DBNavigator1: TDBNavigatorLeft=184Top=224Width=240Height=25DataSource=DataSource1Flat=TrueTabOrder=10Procedure TForm1.Edit1Click(Sender:TObject); BeginEdit2.Text:=' 'Edit3.Text:=' ';End;Procedure TForm1.Edit2Click(Sender:Tobject); BeginEdit1.Text:=' 'Edit3.Text:=' ';End;Procedure TForm1.Edit3Click(Sender:Tobject);BeginEdit2.Text:=' 'Edit1.Text:=' ';End;执行按钮的程序代码如下:Procedure TForm1.Button1Click(Sender:Tobject);BeginTable1.refresh;With table1 doTryDisablecontrols;Filtered:=false;If edit1.text<>' ' then memo1.text:='客户姓名'+' ' ' '+edit1.text+' ' ' ';If edit2.text<>' ' then memo1.text:='房间号'+' ' ' '+edit2.text;If edit3.text<>' ' then memo1.text:='入住时期'+' ' ' '+edit1.text+' ' ' ';Filter:=memo1.text;Filtered:=true;FinallyEnablecontrols;If dbedit1.text=' ' then begin Messagebeep(1);Showmessage(' 没有符合条件的记录,请确认条件或放弃查询~'); If messageDlg(' 是否继续查询,只有结束查询才能作其他操作~',mtinformation,[mbyes,mbno],0)=mrno then beginFiltered:=false;Table1.close;Table1.open;End;End else beginIf messageDlg('是否继续查询,只有结束查询才能作其他操作~',mtinformation,[mbyes,mbno],0)=mrno then beginFiltered:=false;Table1.close;Table1.open;End;End;End;End;第二页各个控件的属性描述如下:Object Tabsheet2: TtabsheetCaption=客房查询Object Labell2: TlabelLeft=215Top=10Width=114Height=19Caption=客户查询系统Font.Height=-19=宋体Object Labell3: Tlabel Left=24Top=200Width=60Height=12Caption=按姓名查询Object Labell4: Tlabel Left=24Top=224Width=60Height=19Caption=按房号查询Object Labell5: Tlabel Left=23Top=246Width=60Height=12Caption=按时期查询endObject DBFrid1: TDBGrid Left=8Top=40Width=553Height=140DataSource=DataSource1 TitleFont.Height=-12 =宋体Object Edit1:TeditLeft=93Top=197Width=102Hdight=20Text=Edit1Object Edit2:TeditLeft=93Top=218Width=103Hdight=20Text=Edit2Object Edit3:TeditLeft=93Top=241Width=103Hdight=20Text=Edit3Object Button1:TbuttonLeft=232Top=208Width=75Height=25Caption='执行查询'Object Memo1:TmemoLeft=372Top=189Width=185Height=61Visible=False第三页面命令控件代码:Procedure TForm1.Button2Click(Sender:Tobject); VarSum1:real;S:string;Bookmark1:tbookmark; BeginSum1=0.00;Bookmark1:=table1.getbookmark;Table1.disablecontrols; Table1.first;While not table1.eof do BeginSum1:=sum1+table1.fieldbyname('结算费用')。
原生JS实现日历组件的示例代码
原⽣JS实现⽇历组件的⽰例代码想要实现的效果点击⽇期选择框出现⽇历有个⽇期控制栏帮助选择⽇期,包括年、⽉、⽇的选择和今天⽇历格⼦,初次点击⽇期选择框时显⽰此刻的⽇期,⽇历格⼦的⽇期应该包括这个⽉的所有天数,同时如果当⽉的1号不是周⽇,还应补全从周⽇到1号的天数。
还要在这个⽉最后1号的后⾯补全到周六。
⽇期控制栏和⽇历格⼦的⽇期还有选择框⾥的⽇期的变化要是同步的。
实现思路为了组件的可复⽤性,需要⽤⾯向对象的思想。
每个⽇历组件都是⼀个⽇历对象,主要包括⽇期选择框,⽇期控制显⽰栏,还有⽇历格⼦,为了保持⽇期控制显⽰栏和⽇历格⼦⽇期同步变化,⽇期控制栏和⽇历⾥⾯的每个格⼦都应该包含⼀个Date属性,点击⽇历⾥的格⼦,将格⼦存的Date属性作为函数参数,调⽤函数改变⽇期控制栏显⽰的时间。
同理,⽇期控制栏时间变化时,也将Date属性作为参数调⽤函数,函数重新绘制⽇历格⼦。
上码:function Calendar(parentId) {this.parentElement = document.getElementById(parentId);this.init();}Calendar.prototype = {init: function() {this.contains = document.createElement("div");this.contains.onselectstart = function(){return false}; //让按钮点击时不会出现⽂字被选中的蓝⾊块this.dateInput = document.createElement("input");this.datePicker = document.createElement("div");this.showDateBar = document.createElement("div");this.dateBox = document.createElement("div");this.icon = document.createElement("i");this.contains.className = 'datepicker-container';this.dateInput.className = 'date-input';this.dateInput.readOnly = true;var parent = this;this.dateInput.onclick = function(event){parent.onDateInputClick(event); //点击⽇期选择框时显⽰⽇历格⼦};this.contains.onblur = function(){parent.datePicker.style.display = 'none';}this.datePicker.className = 'date-picker';this.datePicker.style.display = 'none';this.showDateBar.className = 'show-date';this.dateBox.className = 'date-box';this.icon.className = 'date-icon';this.icon.innerHTML = ' '; //iconfont这⾥⽤的阿⾥图标,可以⾃⾏替换this.datePicker.appendChild(this.showDateBar);this.datePicker.appendChild(this.dateBox);this.contains.appendChild(this.dateInput);this.contains.appendChild(this.icon);this.contains.appendChild(this.datePicker);this.parentElement.appendChild(this.contains);},}初始化⽇期控制栏:drawShowDateBar: function(parentElement){var parent = this;var nowDate = new Date();parentElement.date = nowDate;var nowYear = nowDate.getFullYear();var nowMonth = nowDate.getMonth();var nowDay = nowDate.getDate();//showDateBar内容拼接var contentStr ='<div class="year-input"><span>'+nowYear+'年</span><i class="select-year-btn"> </i><ul class="year-select-box" style="display : none">'; for(var i=0;i<150;i++){contentStr+='<li>'+(i+1900)+'年</li>';}contentStr+='</ul></div>'+'<div class="month-input"><i class="prev-month"> </i><select class="months-options">'for(var i=0;i<12;i++){contentStr+='<option>'+(i+1)+'⽉</option>';}contentStr+='</select><i class="next-month"> </i></div>'+'<div class="day-input"><i class="prev-day"> </i><select class="days-options"></select>'+'<i class="next-day"> </i></div>'+'<button class="today-btn">今天</button>'+'<div class="days-title">';var weekday = ['⽇', '⼀', '⼆', '三', '四', '五', '六'];for (var i = 0; i < 7; i++) {contentStr+='<span class="day-title">'+weekday[i]+'</span>';}contentStr+='</div>';parentElement.innerHTML = contentStr;this.changeShowDateBar(nowDate); //插⼊到showTimeBar之后,初始化,传⼊的参数是现在的时间var yearInput = parentElement.firstChild;//年选择框点击显⽰和隐藏选择列表yearInput.onclick = function(){ //target和this的区别 target是触发事件的元素,this是处理事件的元素var ul = stChild;ul.style.display==='none'||ul.style.display==='none'? ul.style.display='inline-block':ul.style.display='none';};//为年选择下拉框绑定点击事件var yearSelectBox = stChild;var yearLi = yearSelectBox.children;for(var i=0;i<yearLi.length;i++){yearLi[i].onclick = function(){parent.showDateBar.date.setFullYear(this.innerText.slice(0,-1));parent.changeShowDateBar(parent.showDateBar.date); //时间改变之后都要重新调⽤,因为不同年,不同⽉,某个⽉的天数不全⼀样 };}//为month的前后按钮添加点击事件var monthInput = yearInput.nextSibling;monthInput.firstChild.onclick = function(){var monthOptions = this.nextSibling;if(monthOptions.selectedIndex>0){parent.showDateBar.date.setMonth(--monthOptions.selectedIndex);}else{monthOptions.selectedIndex = 11;parent.showDateBar.date.setFullYear(parent.showDateBar.date.getFullYear()-1);parent.showDateBar.date.setMonth(11);}parent.changeShowDateBar(parent.showDateBar.date);};stChild.onclick = function(){var monthOptions = this.previousSibling;if(monthOptions.selectedIndex<11){parent.showDateBar.date.setMonth(++monthOptions.selectedIndex);}else{monthOptions.selectedIndex = 0;parent.showDateBar.date.setFullYear(parent.showDateBar.date.getFullYear()+1);parent.showDateBar.date.setMonth(0);}parent.changeShowDateBar(parent.showDateBar.date);}monthInput.children[1].onchange = function(){parent.showDateBar.date.setMonth(this.selectedIndex);parent.changeShowDateBar(parent.showDateBar.date)};//为day的前后按钮添加点击事件var dayInput = monthInput.nextSibling;dayInput.firstChild.onclick = function(){var dayOptions = this.nextSibling;if(dayOptions.selectedIndex>0){parent.showDateBar.date.setDate(dayOptions.selectedIndex--);}else{parent.showDateBar.date.setMonth(parent.showDateBar.date.getMonth()-1);parent.showDateBar.date.setDate(parent.getDaysOfMonth(parent.showDateBar.date));}parent.changeShowDateBar(parent.showDateBar.date);};stChild.onclick = function(){var dayOptions = this.previousSibling;if(dayOptions.selectedIndex < dayOptions.length-1){dayOptions.selectedIndex++;parent.showDateBar.date.setDate(dayOptions.selectedIndex+1);}else{parent.showDateBar.date.setDate(1);parent.showDateBar.date.setMonth(parent.showDateBar.date.getMonth()+1);}parent.changeShowDateBar(parent.showDateBar.date);};dayInput.children[1].onchange = function(){parent.showDateBar.date.setDate(this.selectedIndex+1);parent.changeShowDateBar(parent.showDateBar.date)};//为今天按钮绑定点击事件var todayBtn = dayInput.nextSibling;todayBtn.onclick = function(){parent.drawPicker(new Date());parent.changeShowDateBar(new Date());}},drawShowDateBar函数为⽇期控制栏的年份、⽉份、和天的点击按钮设置了点击事件处理函数。
携程js日期选择空间最新版
* Tuna JavaScript Library
* /
*
* Copyright(C) 2008 - 2012, Ctrip All rights reserved.
* Version: 090501
*
* Date: 2010-1-13
Hale Waihona Puke / ;var cs_domain=(document.domain||"").match(/ctrip(travel)?\.com$/);window.__uidc_init=1*new Date;var _=window,__=document,___=__.documentElement,Ctrip={module:{}},$topWin=_,$$={},$jsTunaVersion="tuna_100324";_.module={};_.module.event={};(function(){try{for(;;){var a=$topWin.parent;if(a&&a!=$topWin&&a.Ctrip)$topWin=a;else break}}catch(b){}})(); $$.browser=function(a){var b=/opera/.test(a),c=/chrome/.test(a),e=/webkit/.test(a),f=!c&&/safari/.test(a),h=!b&&/msie/.test(a),d=h&&/msie 7/.test(a),g=h&&/msie 8/.test(a),i=h&&/msie 9/.test(a),m=h&&!d&a
JS实现一个简单的日历
JS实现⼀个简单的⽇历主要分为三个部分,1:获取li元素 2:如何填写对应的⽇期 3:如何获取点击li元素的事件。
1:通过节点间关系的属性children 获取li元素(两个for循坏遍历);2:在遍历填写⽇期时,在第⼀⾏判断在当⽉的第⼀天在星期⼏,然后从第⼀天开始填写,直到⼤于当⽉的天数就暂停填写,并开始填写下个⽉的⽇期。
第⼀⾏上个⽉的⽇期显⽰ : 上⽉天数显⽰开始值 = 计算上个⽉的天数 - 这个⽉开始的第⼀天在星期⼏的值 -1,然后在第⼀⾏上⽉天数显⽰开始值⾃加。
3:利⽤JS的事件冒泡获取li的innerHTML显⽰出对应⽇期效果图:代码如下:<!doctype html><html lang="en"><head><meta charset="UTF-8"><meta name="Generator" content="EditPlus®"><meta name="Author" content=""><meta name="Keywords" content=""><meta name="Description" content=""><title>calendar</title><style>.clear:after{content:"";display:table;clear:both;}.left{float:left;}ul{padding:0px;margin-top:5px;margin-bottom:0px;}ul>li{float:left;list-style:none;width:30px;height: 21px;border: 1px solid #ccc;text-align:center;}.gray{color:#766565;}.top {height:25px;}.top .lf-tri{border:10px solid transparent;border-right-color:black;margin-top:4px;}.top .rf-tri{border:10px solid transparent;border-left-color:black;margin-top:4px;}.top .content{width:185px;height:5px;text-align:center;}</style></head><body><div class="top clear"><div class="left lf-tri" onclick="lastMonth()"></div> <div class="left content">2017年2⽉1⽇</div><div class="left rf-tri" onclick=" nextMonth()"></div> </div><div><div id="week"><ul class="clear"><li>⽇</li><li>⼀</li><li>⼆</li><li>三</li><li>四</li><li>五</li><li>六</li><ul></div><div id="date" onclick='getDateNum(event)'><ul class="clear"><li>30</li><li>31</li><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li></ul><ul class="clear"><li>6</li><li>7</li><li>8</li><li>9</li><li>10</li><li>11</li><li>12</li></ul><ul class="clear"><li>13</li><li>14</li><li>15</li><li>16</li><li>17</li><li>18</li><li>19</li></ul><ul class="clear"><li>20</li><li>21</li><li>22</li><li>23</li><li>24</li><li>25</li><li>26</li></ul><ul class="clear"><li>27</li><li>28</li><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li></ul><ul class="clear"><li>27</li><li>28</li><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li></ul></div><div><script>function $(id){return document.getElementById(id);}function change(cls){return document.getElementsByClassName(cls);}function getDateNum(e) {console.log(e && e.target.nodeName)//打印发⽣事件的元素,再获取元素nodeName if(e.target.nodeName=="LI"){//先判断nodeName是LIif(e.target.className!="gray"){//点击本⽉的⽇期,显⽰在⽇期栏change("content")[0].innerHTML = year+'年'+(month+1)+'⽉'+e.target.innerHTML+'⽇'; }else{//点击灰⾊⽇期即(上个⽉或者下个⽉⽇期)切换到当⽉if(e.target.innerHTML>14){lastMonth();}else {nextMonth();}}}}//获取年、⽉var today = new Date();var year=today.getFullYear(), month = today.getMonth();var totalDay;var uls=$("date").children,list;function loadCalendar(){totalDay=getMonthDays(year,month+1);//计算⼀个⽉的天数var firstDay = (new Date(year,month,1)).getDay();//计算每个⽉1号在星期⼏var lastMonthDay=getMonthDays(year,month);var lastDayCal=lastMonthDay-firstDay+1;//计算上个⽉在第⼀⾏显⽰的天数//获取ul元素var num=1 ,nextNum=1;//⽇期显⽰// 类数组对象转数组//uls = Array.prototype.slice.call(uls)//获取li元素填充for(var r=0;r<uls.length;r++){list=uls[r].children;//遍历ul,获得lifor(var line=0;line<list.length;line++){if(r==0){//在第⼀⾏与第⼀天进⾏判断⼤于等于第⼀天时载⼊⽇期if(line>=firstDay){list[line].innerHTML=num++;list[line].setAttribute("class","");}else {list[line].innerHTML=lastDayCal++;//第⼀⾏的上个⽉天数显⽰list[line].setAttribute("class","gray");}}else {//判断是否超出天数 ,不超出则继续加,超出则显⽰下个⽉⽇期if(num<=totalDay){list[line].setAttribute("class","");list[line].innerHTML=num++;}else {list[line].innerHTML=nextNum++;//下个⽉⽇期显⽰list[line].setAttribute("class","gray");}}}}}loadCalendar();function getMonthDays(year,month){//判断2⽉份天数if(month==2){days= (year%4==0)&&(year%100!=0)||(year%400==0)? 29:28;}else {//1-7⽉单数⽉为31⽇if(month<7){days= month%2==1?31:30;}else {//8-12⽉双⽉为31⽇days = month%2==0?31:30;}}return days;}//右击箭头下个⽉//change("rf-tri")[0].onclick =function nextMonth() {month++;if(month>11){year+=1;month=0;}change("content")[0].innerHTML=year+"年"+(month+1)+"⽉"+"1⽇";//console.log(month+1);loadCalendar();}//左击箭头上个⽉//change("lf-tri")[0].onclick =function lastMonth() {month--;if(month<0){month=11;year-=1;}change("content")[0].innerHTML=year+"年"+(month+1)+"⽉"+"1⽇";//console.log(month+1);loadCalendar();}</script></body></html>以上就是本⽂的全部内容,希望本⽂的内容对⼤家的学习或者⼯作能带来⼀定的帮助,同时也希望多多⽀持!。
Javascript日期控件例子
效果图如下代码<script>String.prototype.Format = function(){var tmpStr = this;var iLen = arguments.length;for(var i=0;i<iLen;i++){tmpStr = tmpStr.replace(new RegExp("\\{" + i + "\\}", "g"), arguments[i]); }return tmpStr;}Calendar = {//region Propertytoday : new Date(),year : 2005,month : 8,date : 21,curPosX : 0,curPosY : 0,curCapture : null,curDay : null,//endregion//region Methoddisplay :function(o, e, d){with(Calendar){o = typeof(o) == "object" ? o : document.getElementById(o);if(window.event){curPosX = document.body.scrollLeft + event.x;curPosY = document.body.scrollTop + event.y;} else{curPosX = e.pageX;curPosY = e.pageY;if(o.value == "" && d) o.value = d;with(document.getElementById("Calendar__")){if(o != curCapture) {curCapture = o;if(style.display == "block"){style.left = curPosX + "px";style.top = curPosY + "px";}else load();}else{if (style.display == "block") style.display = "none";else load();}}}},load :function(){with(Calendar){curDay = loadDate(curCapture.value);with(curDay){year = getFullYear();month = getMonth() + 1;date = getDate();}init();}},init :function(){with(Calendar){with(new Date(year, month-1, date)){year = getFullYear();month = getMonth() + 1;date = getDate();setDate(1);var first = getDay();setMonth(getMonth()+1, 0)paint(first, getDate());}}},paint :function(first, last){var calendar = document.getElementById("Calendar__");var grid = document.getElementById("dataGrid__");var i, l;l = Math.ceil((first + last)/7);if(!document.all){calendar.style.height = (41 + 19 * Math.ceil((first + last)/7)) + "px";}grid.innerHTML = new Array(l*7 + 1).join("<li><a></a></li>");with(Calendar){var strDate = "{0}-{1}".Format(year, month);var isTodayMonth = ((year == today.getFullYear()) && (month == today.getMonth() + 1));var isCurdayMonth = ((year == curDay.getFullYear()) && (month == curDay.getMonth() + 1));var todayDate = today.getDate();for(i=0;i<last;i++){grid.childNodes[first + i].innerHTML = '<a href="{2}-{1}"{0} onclick="Calendar.setValue({1});return false">{1}</a>'.Format(((i+1) == todayDate && isTodayMonth) ? ' class="today"' : isCurdayMonth && (i+1) == curDay.getDate()?' class="curDay"':'', i + 1, strDate);}document.getElementById("dateText__").innerHTML = '<a href="' + (year-1) + '年" onclick="Calendar.turn(-12);return false" title="上一年"><<</a> <a href="上一月" onclick="Calendar.turn(-1);return false" title="上一月"><</a> ' + year + " - " + month + ' <a href="下一月" onclick="Calendar.turn(1);return false" title="下一月">></a> <a href="' + (year+1) + '年" onclick="Calendar.turn(12);return false" title="下一年">>></a>';with(calendar){style.left = Calendar.curPosX + "px";style.top = Calendar.curPosY + "px";style.display = "block";}}},turn :function(num){Calendar.month += num;Calendar.date = 1;Calendar.init();},setValue :function(val){with(Calendar){curCapture.value = "{0}-{1}-{2}".Format(year, month, val);document.getElementById("Calendar__").style.display = "none";}},loadDate :function(op, formatString){formatString = formatString || "ymd";var m, year, month, day;switch(formatString){case "ymd" :m = op.match(new RegExp("^((\\d{4})|(\\d{2}))([-./])(\\d{1,2})\\4(\\d{1,2})$"));if(m == null ) return new Date();day = m[6];month = m[5]*1;year = (m[2].length == 4) ? m[2] : GetFullYear(parseInt(m[3], 10));break;case "dmy" :m = op.match(new RegExp("^(\\d{1,2})([-./])(\\d{1,2})\\2((\\d{4})|(\\d{2}))$"));if(m == null ) return new Date();day = m[1];month = m[3]*1;year = (m[5].length == 4) ? m[5] : GetFullYear(parseInt(m[6], 10));break;default :break;}if(!parseInt(month)) return new Date();month = month==0 ?12:month;var date = new Date(year, month-1, day);return (typeof(date) == "object" && year == date.getFullYear() && month == (date.getMonth()+1) && day == date.getDate())?date:new Date();function GetFullYear(y){return ((y<30 ? "20" : "19") + y)|0;}},toString : function(){return ["Calendar v1.0", "author:我佛山人", "email:wfsr@", "version:1.0"].join("\n");}//endregion}var __calendar_html = "<style>";__calendar_html += "#Calendar__ {background-color:#eeeeee;width:157 !important;width:154px;position:absolute;display:none}";__calendar_html += "#Calendar__ ul{list-style-type:none;margin-left:-38px !important;margin:0 0 0 -30px;}"; __calendar_html += "#Calendar__ ul li{display:block;width:20px;margin:1px;background-color:#fff;text-align:center;float:left;font:11px Tahoma}"; __calendar_html += "#Calendar__ ul li a{height:18px;display:block;background-color:#fff;line-height:18px;text-decoration:none;color:#333}";__calendar_html += "#Calendar__ ul li a:hover{background:#336699;color:#FFF}";__calendar_html += "#Calendar__ #dateText__{font:12px Tahoma;text-align:center}";__calendar_html += "#Calendar__ #dateText__ a{font:10px Tahoma;text-decoration:none}";__calendar_html += "#Calendar__ #head__ li a{font:bold 12px Tahoma}";__calendar_html += "#Calendar__ #dataGrid__{}";__calendar_html += "#Calendar__ #dataGrid__ li a:hover{background:#dedede url(/plus/calendar/check.gif) right bottom no-repeat;color:red}";__calendar_html += "#Calendar__ #dataGrid__ .today{background:url(/plus/calendar/today.gif) center no-repeat;color:blue;}";__calendar_html += "#Calendar__ #dataGrid__ .curDay{background:#dedede url(/plus/calendar/check.gif) right bottom no-repeat;color:blue;}";__calendar_html += "</style>";__calendar_html += "<div id=\"Calendar__\">";__calendar_html += "<div id=\"dateText__\"></div>";__calendar_html += "<ul id=\"head__\" onclick=\"return false\">";__calendar_html += "<li><a href=\"#\">日</a></li><li><a href=\"#\">一</a></li><li><a href=\"#\">二</a></li><li><a href=\"#\">三</a></li><li><a href=\"#\">四</a></li><li><a href=\"#\">五</a></li><li><a href=\"#\">六</a></li>";__calendar_html += "</ul>";__calendar_html += "<ul id=\"dataGrid__\"></ul>";__calendar_html += "</div>";document.write(__calendar_html);</script><input type="text" id="demo"><img src="calendar.gif" align="absmiddle" onclick="Calendar.display('demo', event, '2010-11-15s')"><br><input type="text" id="demo1"><img src="calendar.gif" align="absmiddle" onclick="Calendar.display('demo1', event)">示例2.效果图如下代码:<script LANGUAGE="javascript">var months = new Array("一", "二", "三","四", "五", "六", "七", "八", "九","十", "十一", "十二");var daysInMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31,30, 31, 30, 31);var days = new Array("日","一", "二", "三","四", "五", "六");var classTemp;var today=new getToday();var year=today.year;var month=today.month;var newCal;function getDays(month, year) {if(1== month) return((0== year % 4) && (0!= (year % 100))) ||(0 == year % 400) ? 29 : 28;else return daysInMonth[month];}function getToday() {this.now = new Date();this.year = this.now.getFullYear();this.month = this.now.getMonth();this.day = this.now.getDate();}function Calendar() {newCal = new Date(year,month,1);today = new getToday();var day = -1;var startDay = newCal.getDay();var endDay=getDays(newCal.getMonth(),newCal.getFullYear());var daily = 0;if ((today.year == newCal.getFullYear()) &&(today.month == newCal.getMonth())){day = today.day;}var caltable = document.all.caltable.tBodies.calendar;var intDaysInMonth =getDays(newCal.getMonth(),newCal.getFullYear());for (var intWeek = 0; intWeek <caltable.rows.length;intWeek++)for (var intDay = 0;intDay <caltable.rows[intWeek].cells.length;intDay++){var cell = caltable.rows[intWeek].cells[intDay];varmontemp=(newCal.getMonth()+1)<10?("0"+(newCal.getMonth()+ 1)):(newCal.getMonth()+1);if ((intDay == startDay) && (0 == daily)){ daily = 1;} var daytemp=daily<10?("0"+daily):(daily);vard="<"+newCal.getFullYear()+"-"+montemp+"-"+daytemp+">";if(day==daily) cell.className="DayNow";else if(intDay==6) cell.className = "DaySat";else if (intDay==0) cell.className ="DaySun";else cell.className="Day";if ((daily > 0) && (daily <= intDaysInMonth)){cell.innerText = daily;daily++;} else{cell.className="CalendarTD";cell.innerText = "";}}document.all.year.value=year;document.all.month.value=month+1;}function subMonth(){if ((month-1)<0){month=11;year=year-1;} else{month=month-1;}Calendar();}function addMonth(){if((month+1)>11){month=0;year=year+1;} else{month=month+1;}Calendar();}function setDate(){if(document.all.month.value<1||document.all.month.value>12) {alert("月的有效范围在1-12之间!");return;}year=Math.ceil(document.all.year.value);month=Math.ceil(document.all.month.value-1);Calendar();}</Script><script>function buttonOver(){var obj = window.event.srcElement;obj.runtimeStyle.cssText = "background-color:#FFFFFF";// obj.className="Hover";}function buttonOut(){var obj = window.event.srcElement;window.setTimeout(function(){obj.runtimeStyle.cssText = "";},300);}</Script><Style>Input {font-family: verdana;font-size: 9pt;text-decoration: none;background-color: #FFFFFF;height: 20px;border: 1px solid #666666;color:#000000;}.Calendar {font-family: verdana;text-decoration: none;width: 170;background-color: #C0D0E8;font-size: 9pt;border:0px dotted #1C6FA5;}.CalendarTD {font-family: verdana;font-size: 7pt;color:#000000;background-color:#f6f6f6;height:20px;width:11%;text-align: center;}.Title {font-family: verdana;font-size: 11pt;font-weight: normal;height: 24px;text-align: center;color:#333333;text-decoration: none;background-color:#A4B9D7;border-top-width: 1px;border-right-width:1px;border-bottom-width: 1px;border-left-width:1px;border-bottom-style:1px;border-top-color:#999999;border-right-color: #999999;border-bottom-color: #999999;border-left-color: #999999;}.Day {font-family: verdana;font-size:7pt;color:#243F65;background-color: #E5E9F2;height:20px;width:11%;text-align: center;}.DaySat {font-family: verdana;font-size:7pt;color:#FF0000;text-decoration:none;background-color:#E5E9F2;text-align: center;height: 18px;width: 12%;}.DaySun {font-family: verdana;font-size: 7pt;color:#FF0000;text-decoration:none;background-color:#E5E9F2;text-align: center;height: 18px;width: 12%;}.DayNow {font-family: verdana;font-size: 7pt;font-weight: bold;color: #000000;background-color: #FFFFFF;height:20px;text-align: center;}.DayTitle {font-family: verdana;font-size: 9pt;color:#000000;background-color: #C0D0E8;height:20px;width:11%;text-align: center;}.DaySatTitle {font-family: verdana;font-size:9pt;color:#FF0000;text-decoration:none;background-color:#C0D0E8;text-align: center;height: 20px;width: 12%;}.DaySunTitle {font-family: verdana;font-size: 9pt;color:#FF0000;text-decoration: none;background-color:#C0D0E8;text-align: center;height: 20px;width: 12%;}.DayButton {font-family: Webdings;font-size: 9pt;font-weight: bold;color: #243F65;cursor:hand;text-decoration: none;}</Style><table border="0" cellpadding="0" cellspacing="1"class="Calendar" id="caltable"><thead><tr align="center" valign="middle"><td colspan="7" class="Title"><a href="javascript:subMonth();" title="上一月"Class="DayButton">3</a><input name="year" type="text"size="4" maxlength="4" onkeydown="if(event.keyCode==13){setDate()}"onkeyup="this.value=this.value.replace(/[^0-9]/g,'')" onpaste="this.value=this.value.replace(/[^0-9]/g,'')">年<input name="month" type="text" size="1" maxlength="2" onkeydown="if (event.keyCode==13){setDate()}"onkeyup="this.value=this.value.replace(/[^0-9]/g,'')" onpaste="this.value=this.value.replace(/[^0-9]/g,'')">月<a href="javascript:addMonth();" title="下一月"Class="DayButton">4</a></td></tr><tr align="center" valign="middle"><script LANGUAGE="javascript">document.write("<TD class=DaySunTitle id=diary >"+ days[0] + "</TD>");for (var intLoop = 1; intLoop < days.length-1;intLoop++) document.write("<TD class=DayTitle id=diary>" +days[intLoop] + "</TD>");document.write("<TD class=DaySatTitle id=diary>" +days[intLoop] + "</TD>");</Script></TR></thead><TBODY border=1 cellspacing="0" cellpadding="0"ID="calendar" ALIGN=CENTER oNCLICK="getDiary()"><script LANGUAGE="javascript">for (var intWeeks = 0; intWeeks < 6; intWeeks++){document.write("<TR style='cursor:hand'>");for (var intDays = 0; intDays < days.length;intDays++)document.write("<TD class=CalendarTDonMouseover='buttonOver();'onMouseOut='buttonOut();'></TD>");document.write("</TR>");}</Script></TBODY></TABLE><script LANGUAGE="javascript">Calendar();</Script>示例3.效果图如下代码如下:<script language="javascript">document.write("<DIV id='cc' style='BORDER-RIGHT: #000000 1px solid; PADDING-RIGHT: 12px; BORDER-TOP: #000000 1px solid; PADDING-LEFT: 12px; Z-INDEX: 2; BACKGROUND: #ffffff; FILTER: Alpha(opacity=85); LEFT: 505px; VISIBILITY: hidden; PADDING-BOTTOM: 12px; BORDER-LEFT: #000000 1px solid; WIDTH: 200px; LINE-HEIGHT: 22px; PADDING-TOP: 12px; BORDER-BOTTOM: #000000 1px solid; POSITION: absolute; TOP: 419px; HEIGHT: 90px'></DIV>");document.write("<style>td {font-family: Arial, Helvetica, sans-serif;font-size: 12px;}table{border-collapse:collapse} .sel{font-family: Webdings;font-size: 9pt;font-weight: bold;color: #243F65;cursor:hand;text-decoration: none; background-color:DEDEEF}body {margin-left:0px;margin-top: 0px;}</style>")var name;function dateSelect(objname){cc.style.visibility="visible";cc.style.filter="Alpha(opacity=85)"cc.style.left=document.body.scrollLeft+window.event.clientX+2;cc.style.top=document.body.scrollTop+window.event.clientY+2;name = objname;showSelect();}function hiddeninfo(){cc.style.visibility="hidden";}function RunNian(The_Year){if ((The_Year%400==0) || ((The_Year%4==0) && (The_Year%100!=0))) return true;elsereturn false;}function GetWeekday(The_Year,The_Month){var Allday;Allday = 0;if (The_Year>2000){for (i=2000;i<The_Year; i++){if (RunNian(i)) {Allday += 366;}else {Allday += 365;}}for (i=2; i<=The_Month; i++){switch (i){case 2 :if (RunNian(The_Year))Allday += 29;elseAllday += 28;break;case 3 : Allday += 31; break;case 4 : Allday += 30; break;case 5 : Allday += 31; break;case 6 : Allday += 30; break;case 7 : Allday += 31; break;case 8 : Allday += 31; break;case 9 : Allday += 30; break;case 10 : Allday += 31; break;case 11 : Allday += 30; break;case 12 : Allday += 31; break;}}}return (Allday+6)%7;}function chooseday(The_Year,The_Month,The_Day){var Firstday;var completely_date;if (The_Day!=0)completely_date = The_Year + "-" + The_Month + "-" + The_Day;elsecompletely_date = "";//showdate 只是一个为了显示而采用的东西,//如果外部想引用这里的时间,可以通过使用completely_date引用完整日期//也可以通过The_Year,The_Month,The_Day分别引用年,月,日//当进行月份和年份的选择时,认为没有选择完整的日期Firstday = GetWeekday(The_Year,The_Month);ShowCalender(The_Year,The_Month,The_Day,Firstday);}function chooses(The_Year,The_Month,The_Day){var obj2 = document.getElementById(name);var Firstday;var completely_date;if (The_Day!=0)completely_date = The_Year + "-" + The_Month + "-" + The_Day;elsecompletely_date = "";obj2.value = completely_date;hiddeninfo();}function nextmonth(The_Year,The_Month){if (The_Month==12)chooseday(The_Year+1,1,0,name);elsechooseday(The_Year,The_Month+1,0,name);}function prevmonth(The_Year,The_Month){if (The_Month==1)chooseday(The_Year-1,12,0);elsechooseday(The_Year,The_Month-1,0);}function prevyear(The_Year,The_Month){chooseday(The_Year-1,The_Month,0);}function nextyear(The_Year,The_Month){chooseday(The_Year+1,The_Month,0);}function ShowCalender(The_Year,The_Month,The_Day,Firstday){var ycdate="";var showstr;var Month_Day;var ShowMonth;var today;today = new Date();switch (The_Month){case 1 : ShowMonth = "1月"; Month_Day = 31; break;case 2 :ShowMonth = "2月";if (RunNian(The_Year))Month_Day = 29;elseMonth_Day = 28;break;case 3 : ShowMonth = "3月"; Month_Day = 31; break;case 4 : ShowMonth = "4月"; Month_Day = 30; break;case 5 : ShowMonth = "5月"; Month_Day = 31; break;case 6 : ShowMonth = "6月"; Month_Day = 30; break;case 7 : ShowMonth = "7月"; Month_Day = 31; break;case 8 : ShowMonth = "8月"; Month_Day = 31; break;case 9 : ShowMonth = "9月"; Month_Day = 30; break;case 10 : ShowMonth = "10月"; Month_Day = 31; break;case 11 : ShowMonth = "11月"; Month_Day = 30; break;case 12 : ShowMonth = "12月"; Month_Day = 31; break;}showstr = "";showstr = "<Table cellpadding=0 cellspacing=0 border=1 bordercolor=#C0D0E8 width=95% align=center valign=top>"; //上边框颜色showstr += "<tr><td width=0 class='sel' onclick=prevyear("+The_Year+"," + The_Month + ")>3</td><td width=0> " + The_Year + "年 </td><td width=0onclick=nextyear("+The_Year+","+The_Month+") class='sel'>4</td><td width=0 class='sel' onclick=prevmonth("+The_Year+","+The_Month+")>3</td><td width=40 align=center>" + ShowMonth + "</td><td width=0 onclick=nextmonth("+The_Year+","+The_Month+") class='sel'>4</td></tr>";showstr += "<tr><td align=center width=100% colspan=6>";showstr += "<table cellpadding=0 cellspacing=0 border=1 bordercolor=#C0D0E8 width=100%>";//内边框颜色showstr += "<Tr align=center bgcolor=#C0D0E8> ";//星期td背景showstr += "<td><strong><font color=#ff0000>日</font></strong></td>";showstr += "<td><strong><font color=#000000>一</font></strong></td>";showstr += "<td><strong><font color=#000000>二</font></strong></td>";showstr += "<td><strong><font color=#000000>三</font></strong></td>";showstr += "<td><strong><font color=#000000>四</font></strong></td>";showstr += "<td><strong><font color=#000000>五</font></strong></td>";showstr += "<td><strong><font color=#ff0000>六</font></strong></td>";showstr += "</Tr><tr>";for (i=1; i<=Firstday; i++)showstr += "<Td align=center bgcolor=#ffffff> </Td>";//月前空日日期背景for (i=1; i<=Month_Day; i++){if ((The_Year==today.getYear()) && (The_Month==today.getMonth()+1) && (i==today.getDate())){bgColor = "#DEDEEF";//当前日期td颜色ycdate = "<b><font color='#ff0000'>" + i + "</font></b>";}else{bgColor = "#DEDEEF";//大部分td颜色ycdate=i+"";}if (The_Day==i) bgColor = "#ffffff";//选择日期td颜色showstr += "<td align=center bgcolor=" + bgColor + " style='cursor:hand' onclick=chooses(" + The_Year + "," + The_Month + "," + i + ")>" + ycdate + "</td>";Firstday = (Firstday + 1)%7;if ((Firstday==0) && (i!=Month_Day)) showstr += "</tr><tr>";}if (Firstday!=0) {for (i=Firstday; i<7; i++)showstr += "<td align=center bgcolor=#ffffff> </td>";//月尾空日td背景showstr += "</tr>";}showstr += "</tr></table></td></tr><tr><td colspan='7'><div align='center' onclick='hiddeninfo()' style='cursor:hand'>返回</div></td></tr></table>";cc.innerHTML = showstr;}function showSelect(name){var The_Year,The_Day,The_Month;var today;var Firstday;today = new Date();The_Year = today.getYear();The_Month = today.getMonth() + 1;The_Day = today.getDate();Firstday = GetWeekday(The_Year,The_Month);ShowCalender(The_Year,The_Month,The_Day,Firstday);}</script><br><input type="text" id="indate"><span onClick="dateSelect('indate')" >查看</span>。
获取阴历(农历)和当前日期的js代码
获取阴历(农历)和当前⽇期的js代码本⽂为⼤家分享了⼀段js显⽰阴历(农历)和当前⽇期的关键性代码,供⼤家参考,具体内容如下var CalendarData=new Array(100);var madd=new Array(12);var tgString="甲⼄丙丁戊⼰庚⾟壬癸";var dzString="⼦丑寅卯⾠巳午未申⾣戌亥";var numString="⼀⼆三四五六七⼋九⼗";var monString="正⼆三四五六七⼋九⼗冬腊";var weekString="⽇⼀⼆三四五六";var sx="⿏⽜虎兔龙蛇马⽺猴鸡狗猪";var cYear,cMonth,cDay,TheDate;CalendarData = new Array(0xA4B,0x5164B,0x6A5,0x6D4,0x415B5,0x2B6,0x957,0x2092F,0x497,0x60C96,0xD4A,0xEA5,0x50DA9,0x5AD,0x2B6,0x3126E, 0x92E,0x7192D,0xC95,0xD4A,0x61B4A,0xB55,0x56A,0x4155B, 0x25D,0x92D,0x2192B,0xA95,0x7169 madd[0]=0;madd[1]=31;madd[2]=59;madd[3]=90;madd[4]=120;madd[5]=151;madd[6]=181;madd[7]=212;madd[8]=243;madd[9]=273;madd[10]=304;madd[11]=334;function GetBit(m,n){return (m>>n)&1;}function e2c(){TheDate= (arguments.length!=3) ? new Date() : new Date(arguments[0],arguments[1],arguments[2]);var total,m,n,k;var isEnd=false;var tmp=TheDate.getYear();if(tmp<1900){tmp+=1900;}total=(tmp-1921)*365+Math.floor((tmp-1921)/4)+madd[TheDate.getMonth()]+TheDate.getDate()-38;if(TheDate.getYear()%4==0&&TheDate.getMonth()>1) {total++;}for(m=0;;m++){k=(CalendarData[m]<0xfff)?11:12;for(n=k;n>=0;n--){if(total<=29+GetBit(CalendarData[m],n)){isEnd=true; break;}total=total-29-GetBit(CalendarData[m],n);}if(isEnd) break;}cYear=1921 + m;cMonth=k-n+1;cDay=total;if(k==12){if(cMonth==Math.floor(CalendarData[m]/0x10000)+1){cMonth=1-cMonth;}if(cMonth>Math.floor(CalendarData[m]/0x10000)+1){cMonth--;}}}function GetcDateString(){var tmp="";tmp+=tgString.charAt((cYear-4)%10);tmp+=dzString.charAt((cYear-4)%12);tmp+="(";tmp+=sx.charAt((cYear-4)%12);tmp+=")年 ";if(cMonth<1){tmp+="(闰)";tmp+=monString.charAt(-cMonth-1);}else{tmp+=monString.charAt(cMonth-1);}tmp+="⽉";tmp+=(cDay<11)?"初":((cDay<20)?"⼗":((cDay<30)?"廿":"三⼗"));if (cDay%10!=0||cDay==10){tmp+=numString.charAt((cDay-1)%10);}return tmp;}function GetLunarDay(solarYear,solarMonth,solarDay){//solarYear = solarYear<1900?(1900+solarYear):solarYear;if(solarYear<1921 || solarYear>2020){return "";}else{solarMonth = (parseInt(solarMonth)>0) ? (solarMonth-1) : 11;e2c(solarYear,solarMonth,solarDay);return GetcDateString();}}var D=new Date();var yy=D.getFullYear();var mm=D.getMonth()+1;var dd=D.getDate();var ww=D.getDay();var ss=parseInt(D.getTime() / 1000);if (yy<100) yy="19"+yy;function showCal(){document.write(GetLunarDay(yy,mm,dd));}页⾯调⽤代码:<script language="JavaScript" type="text/javascript" src="getCNdate.js"></script><script type="text/javascript">showCal();</script>代码⼆:⽤JavaScript获取当前农历⽇期<script type="text/javascript">var sWeek = new Array("星期⽇","星期⼀","星期⼆","星期三","星期四","星期五","星期六");var dNow = new Date();var CalendarData=new Array(100);var madd=new Array(12);var tgString="甲⼄丙丁戊⼰庚⾟壬癸";var dzString="⼦丑寅卯⾠巳午未申⾣戌亥";var numString="⼀⼆三四五六七⼋九⼗";var monString="正⼆三四五六七⼋九⼗冬腊";var weekString="⽇⼀⼆三四五六" CalendarData = new Array( 0xA4B,0x5164B,0x6A5,0x6D4,0x415B5,0x2B6,0x957,0x2092F,0x497,0x60C96, 0xD4A,0xEA5,0x50DA9,0x5AD,0x2B6,0x3126E, 0x92E,0x7192D,0xC95,0xD4A, 0x61B4A,0xB55,0x56A,0x4155B, 0x25D,0x92D,0x 0x49B,0x41497,0xA4B,0xA164B, 0x6A5,0x6D4,0x615B4,0xAB6,0x957,0x5092F,0x497,0x64B, 0x30D4A,0xEA5,0x80D65,0x5AC,0xAB6,0x5126D,0x92E,0xC96, 0x41A95,0xD4A,0xDA5,0x20B55,0x56A,0x7155B,0x25D,0x92D,0x5192B,0xA95, 0xB4A,0x416AA,0xAD5,0x90AB5,0x4BA,0xA5B, 0x60A57,0x52B,0xA93,0x40E95); madd[0]=0;madd[1]=31;madd[2]=59;madd[3]=90;madd[4]=120;madd[5]=151;madd[6]=181;madd[7]=212;madd[8]=243;madd[9]=273;madd[10]=304;madd[11]=334;function GetBit(m,n) { return (m>>n)&1; }function e2c(){TheDate= (arguments.length!=3) ? new Date() : new Date(arguments[0],arguments[1],arguments[2]);var total,m,n,k;var isEnd=false;var tmp=TheDate.getFullYear();total=(tmp-1921)*365+Math.floor((tmp-1921)/4)+madd[TheDate.getMonth()]+TheDate.getDate()-38; if (TheDate.getYear()%4==0&&TheDate.getMonth()>1) { total++;} for(m=0;;m++) { k=(CalendarData[m]<0xfff)?11:12; for(n=k;n>=0;n--) { if(total<=29+GetBit(C function GetcDateString(){ var tmp=""; tmp+=tgString.charAt((cYear-4)%10);tmp+=dzString.charAt((cYear-4)%12);tmp+="年 ";if(cMonth<1) { tmp+="(闰)"; tmp+=monString.charAt(-cMonth-1); } else {tmp+=monString.charAt(cMonth-1);} tmp+="⽉"; tmp+=(cDay<11)?"初":((cDay<20)?"⼗":((cDay<30)?"廿":"三⼗"));if (cDay%10!=0||cDay==10) { tmp+=numString.charAt((cDay-1)%10); } return tmp;}function GetLunarDay(solarYear,solarMonth,solarDay){if (solarYear<1921 || solarYear>2020) { return "";} else { solarMonth = (parseInt(solarMonth)>0) ? (solarMonth-1) : 11; e2c(solarYear,solarMonth,solarDay); return GetcDateString(); }}var D=new Date();var yy=D.getFullYear();var mm=D.getMonth()+1;var dd=D.getDate();var ww=D.getDay();var ss=parseInt(D.getTime() / 1000);function getFullYear(d){// 修正firefox下year错误yr=d.getYear();if(yr<1000)yr+=1900;return yr;}function showDate() {var sValue = getFullYear(dNow)+"年"+(dNow.getMonth()+1)+"⽉"+dNow.getDate()+"⽇"+" "+sWeek[dNow.getDay()]+" ";sValue+=GetLunarDay(yy,mm,dd);document.getElementById("pDate").innerHTML = sValue;};window.onload=showDate;</script>知道如何获取农历,如何呢获取当前⽇期也很简单。
JS日期操作代码,获取当前日期,加一天,减一天
JS⽇期操作代码,获取当前⽇期,加⼀天,减⼀天全选注:引⼊外部Js需再刷新⼀下页⾯才能执⾏]"/TR/xhtml1/DTD/xhtml1-transitional.dtd"><metacontent="text/html;charset=utf-8" http-equiv="Content-type"/><title>title</title> <inputid="date" type="text"/><input id="Add"type="button"value="加"/> <inputid="Minus" type="button"value="减"/> <scripttype="text/javascript"> $= function(o) { returntypeof o === 'string' ?document.getElementById(o) : o }; //设置当前⽇期var ma =[['1','3','5','7','8','10'],['4','6','9','11']]; var dd =new Date(); var x =dd.toLocaleString(); var o= pasDate(x);$('date').value = o.join('-');//转化⽇期函数 functionpasDate(da) { var yp =da.indexOf('年'), mp =da.indexOf('⽉'), dp =da.indexOf('⽇'); var y =da.substr(0,yp), m =da.substr(yp + 1,mp - yp -1), d = da.substr(mp +1,dp - mp - 1); return[y,m,d]; } //判断数组a是否存在在元素n functioncheck(n,a) { for(var i =0,len = a.length;i <len;i++) { if(a[i] == n) {return true; } } returnfalse; } //闰?年? functionisLeap(y) { return ((y % 4== 0 && y % 100 != 0) || y% 400 == 0) ? true : false;} //实现加减f:'1'加,'0'减function trans(o,f) { var d= o.split('-'); var l =isLeap(d[0]); if(f == '1') {if((check(d[1],ma[0]) &&(d[2] == '31')) ||(check(d[1],ma[1]) &&(d[2] == '30')) || (d[1] == '2'&& d[2] == '28' && !l) ||(d[1] == '2' && d[2] == '29'&& l)) { return d[0] + '-' +。
原生JavaScript实现日历功能代码实例(无引用Jq)
原⽣JavaScript实现⽇历功能代码实例(⽆引⽤Jq)这篇⽂章主要介绍了原⽣JavaScript实现⽇历功能代码实例(⽆引⽤Jq),⽂中通过⽰例代码介绍的⾮常详细,对⼤家的学习或者⼯作具有⼀定的参考学习价值,需要的朋友可以参考下成品显⽰,可左右切换⽉份html 代码<!DOCTYPE html><html><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>移动端⽇历</title><link rel="stylesheet" href="./css/calendar.css" rel="external nofollow" ></head><body><div id="calendarElement"><div class="header"><div class="prev"><i class="previ"></i></div><div class="date"></div><div class="next"><i class="nexti"></i></div></div><div class="content"><div class="week"><div>⽇</div><div>⼀</div><div>⼆</div><div>三</div><div>四</div><div>五</div><div>六</div></div><div class="weekMany clearfloat"></div></div></div><script src="./js/calendar.js"></script></body></html>css代码*{margin: 0;padding: 0;}/*清除浮动代码*/.clearfloat:after{display:block;clear:both;content:"";visibility:hidden;height:0}.clearfloat{zoom:1}#calendarElement{margin: 100px auto;width: 80%;box-shadow: 0 0 10px #999999;}#calendarElement>.header{height: 80px;background-color: coral;display: flex;border-bottom: 1px solid #fff;}#calendarElement>.header .prev{width: 20%;position: relative;}height: 20px;display: block;position: absolute;left: 50%;top: 50%;margin-top: -10px;margin-left: -10px;transform: rotate(45deg);border: 2px solid #fff;border-right: none;border-top: none;}#calendarElement>.header .next{position: relative;}#calendarElement>.header .next i{width: 20px;height: 20px;display: block;position: absolute;left: 50%;top: 50%;margin-top: -10px;margin-left: -10px;transform: rotate(45deg);border: 2px solid #fff;border-left: none;border-bottom: none;}#calendarElement>.header .date{width: 60%;font-size: 22px;line-height: 80px;color: #fff;text-align: center;}#calendarElement>.header .next{width: 20%;}#calendarElement>.content >.week{box-sizing: border-box;width: 100%;height: 40px;color: #fff;display: flex;padding: 0 1%;}#calendarElement>.content >.week >div{width: 14%;text-align: center;line-height: 40px;}#calendarElement>.content >.weekMany{padding-top: 5px;padding-bottom: 15px;}#calendarElement>.content >.weekMany>div{float: left;width: 14.28%;height: 40px;text-align: center;line-height: 40px;font-size: 14px;}#calendarElement>.content >.weekMany>.otherMonth{color: #999999}JS代码var currentTime=""; //当前时间年⽉⽇var dom=document.querySelector("#calendarElement"); //承载元素var color="";getCurrentTime();randomColor();function getCurrentTime(){ //获取当前时间var time=new Date();var year=time.getFullYear();var month=time.getMonth()+1;var day=time.getDate();if(month<10){month="0"+month}var data=year+ "-" +month;currentTime=year+ "-" +month+"-"+day;document.querySelector(".date").innerHTML=data;};dom.addEventListener("click",function(e){if(e.target.className=="previ" || e.target.className=="prev"){getMonths("prev")}else if(e.target.className=="nexti" || e.target.className=="next"){getMonths("next")}})function showDay(){var html="";var MonthOne=currentTime;var yearMonth=currentTime.split('-').slice(0,2);yearMonth=yearMonth.join('-');document.querySelector(".date").innerHTML=yearMonth;MonthOne=MonthOne.split('');MonthOne.splice(8,2,"01")MonthOne=MonthOne.join('');var monthLen=getMonthLength(MonthOne); //每⽉有多少天var weekMany=new Date(MonthOne).getDay(); //每⽉⼀号是星期⼏html+=getPrevMonthHtml(weekMany);html+=getNowMonthHtml(monthLen);html+=getNextMonthHtml(weekMany,monthLen);document.querySelector(".weekMany").innerHTML=html;}function getPrevMonthHtml(weekMany){var html="";var lastMonth=currentTime.substring(0, 7); //得出年⽉lastMonth=lastMonth.split('-')if(lastMonth[1]-1==0){lastMonth[1]=12;lastMonth[0]=lastMonth[0]-1;}else if(lastMonth[1]-1<10){lastMonth[1]="0"+(lastMonth[1]-1);}lastMonth=lastMonth.join('-');var monthLen=getMonthLength(lastMonth);var start=monthLen-weekMany;for(var i=start+1;i<=monthLen;i++){html+='<div class="otherMonth day" data-date="'+lastMonth+'-'+i+'">'+i+'</div>';}return html;}function getNowMonthHtml(monthLen){var html="";var MonthOne=currentTime.substring(0, 7); //得出年⽉var today=currentTime.split('-')[2];for(var i=1;i<=monthLen;i++){if(i<10){var q="0"+i;}else{var q=i;}if(i==today){html+='<div class="thisMonth day" style="background-color:'+color+';color:#fff" data-date="'+MonthOne+'-'+q+'">'+i+'</div>'; }else{html+='<div class="thisMonth day" data-date="'+MonthOne+'-'+q+'">'+i+'</div>';}}return html;}function getNextMonthHtml(weekMany,monthLen){var html="";var daynum=weekMany+monthLen;if(daynum%7==0){}else{var num=daynum%7;var lessNum=7-num; //差⼏天var lowerMonth=currentTime.substring(0, 7); //得出年⽉lowerMonth=lowerMonth.split('-')if(lowerMonth[1]+1==13){lowerMonth[1]="0"+1;lowerMonth[0]=+lowerMonth[0]+1;}else{lowerMonth[1]=+lowerMonth[1]+1;if(lowerMonth[1]<10){lowerMonth[1]="0"+lowerMonth[1];}}lowerMonth=lowerMonth.join('-');for(var i=1;i<=lessNum;i++){if(i<10){var q="0"+i}html+='<div class="otherMonth day" data-date="'+lowerMonth+'-'+q+'">'+i+'</div>';}}return html;}function getMonths(around){if(around=="prev"){currentTime=currentTime.split('-');currentTime[1]=currentTime[1]-1;if(currentTime[1]==0){currentTime[1]="12"currentTime[0]=+currentTime[0]-1}if(currentTime[1]<10){currentTime[1]="0"+currentTime[1]}currentTime=currentTime.join('-');showDay();}else if(around=="next"){currentTime=currentTime.split('-');currentTime[1]=+currentTime[1]+1;if(currentTime[1]==13){currentTime[1]="1"currentTime[0]=+currentTime[0]+1}if(currentTime[1]<10){currentTime[1]="0"+currentTime[1]}currentTime=currentTime.join('-');showDay();}}function getMonthLength(date) { // 获取每⽉有多少天let d = new Date(date)// 将⽇期设置为下⽉⼀号d.setMonth(d.getMonth()+1)d.setDate('1')// 获取本⽉最后⼀天d.setDate(d.getDate()-1)return d.getDate()}function randomColor(){ //随机颜⾊color = '#'+Math.floor(Math.random()*16777215).toString(16);if(color.length==6){color+="0"}document.querySelector(".header").style.backgroundColor=color;document.querySelector(".week").style.backgroundColor=color;};以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。
ihg协议代码
IHG协议代码1. 简介IHG协议代码是一种用于描述酒店预订信息的标准格式,主要用于酒店预订系统之间的数据交换。
本文档将介绍IHG协议代码的基本结构和常用字段。
2. IHG协议代码结构IHG协议代码采用键值对的形式进行表示,每个键值对占据一行。
下面是一个示例:- 酒店名称: IHG酒店- 预订人姓名: 张三- 预订日期: 2022-01-01- 入住日期: 2022-01-02- 离店日期: 2022-01-05- 房间类型: 单人间- 房间数量: 2IHG协议代码使用Markdown文本格式进行输出,以便于人们阅读和编辑。
每个字段都由一个键和一个值组成,中间使用冒号进行分隔。
键和值之间没有空格。
3. 常用字段IHG协议代码中有一些常用的字段,用于描述酒店预订信息。
下面是一些常用字段的示例:•酒店名称: 用于描述预订的酒店名称,例如“IHG酒店”。
•预订人姓名: 用于描述预订人的姓名,例如“张三”。
•预订日期: 用于描述预订的日期,例如“2022-01-01”。
•入住日期: 用于描述入住的日期,例如“2022-01-02”。
•离店日期: 用于描述离店的日期,例如“2022-01-05”。
•房间类型: 用于描述预订的房间类型,例如“单人间”。
•房间数量: 用于描述预订的房间数量,例如“2”。
4. 示例下面是一个完整的IHG协议代码示例:- 酒店名称: IHG酒店- 预订人姓名: 张三- 预订日期: 2022-01-01- 入住日期: 2022-01-02- 离店日期: 2022-01-05- 房间类型: 单人间- 房间数量: 2以上示例中,描述了一个预订了IHG酒店的张三,在2022年1月1日预订了两个单人间,入住日期为2022年1月2日,离店日期为2022年1月5日。
5. 总结IHG协议代码是一种用于描述酒店预订信息的标准格式,采用键值对的形式进行表示。
本文档介绍了IHG协议代码的基本结构和常用字段,并提供了一个示例供参考。
js中日历的代码
js中⽇历的代码Html<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>⽆标题⽂档</title><link rel="stylesheet" href="⽇历样式.css" type="text/css" /><script src="⽇历Js.js" type="text/javascript"></script></head><body><div id="table"><ul><li class="active"><h2>1</h2><P>JAN</P></li><li><h2>2</h2><P>FER</P></li><li><h2>3</h2><P>MAR</P></li><li><h2>4</h2><P>APR</P></li><li><h2>5</h2><P>MAY</P></li><li><h2>6</h2><P>JUN</P></li><li><h2>7</h2><P>JUL</P></li><li><h2>8</h2><P>AUG</P></li><li><h2>9</h2><P>SEP</P></li><li><h2>10</h2><P>OCT</P></li><li><h2>11</h2><P>NOV</P></li><li><h2>12</h2><P>DEC</P></li></ul><div class="div1"><h2>⼀⽉活动</h2><p>快过年了,⼤家商量着去哪玩啊</p></div></div></body></html>css@charset "utf-8";/* CSS Document */#table{width:300px;height:700px;background-color:#CCC;text-align:center;position:absolute;margin:0 600px 0 500px;}#table ul{line-height:10px;}#table ul li{float:left;padding:20px;list-style-type:none;}#table .div1{width:300px;height:200px;background:red;position:absolute;bottom:0px;}#table ul h2 {color:#FFF;}#table ul p {color:#FFF;}.active{background-color:black;}Js// JavaScript Documentwindow.onload=function(){var arr=[' ⼀⽉','⼆⽉','三⽉','四⽉','五⽉','六⽉','七⽉','⼋⽉','九⽉','⼗⽉','⼗⼀⽉','⼗⼆⽉',]var aTal=document.getElementById('table');var aLi=aTal.getElementsByTagName('li');var aDiv1=aTal.getElementsByTagName('div')[0];for (var i=0;i<aLi.length;i++){aLi[i].index=i;aLi[i].onmouseover=function(){for (var i=0;i<aLi.length;i++){aLi[i].className="";}this.className="active";aDiv1.innerHTML= '<h2>'+(this.index+1)+'⽉活动</h2><p>'+arr[this.index]+'</p>'; }}。
日历javascript代码
eval(function(p,a,c,k,e,d){e=function(c){return(c<a?"":e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)d[e(c)]=k[c]||e(c);k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1;};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p;}('k($4j.3X){$f={};19(o p 4i $2l)k(5Z $2l[p]=="6d"){$f[p]={};19(o 4B 4i $2l[p])$f[p][4B]=$2l[p][4B]}q $f[p]=$2l[p]}q $f=$2l;19(p 4i $4j)$f[p]=$4j[p];o $c;k($62){6o.2N.7c("6W",l($){k(!$)h.2h();t $});6o.2N.7b("6N",l(){o $=h.6K;3l($.5f!=1)$=$.7e;t $});7a.2N.2T=l($,b){o A=$.1l(/6C/,"");b.6B=l($){6M.1Q=$;t b()};h.7g(A,b.6B,1n)}}l 5n(){$c=h;h.2F=[];$d=1P.75("x"
酒店入住离店js日历代码
酒店入住离店js日历代码<!DOCTYPE HTML><html><head><meta charset="utf-8"><title>酒店入住离店js日历代码</title><style>body{padding:0;margin:0 10px;}.title{padding:0;margin:10px 0;font:700 18px/1.5 \5fae\8f6f\96c5\9ed1;}.title em{font-style:normal;color:#C00;font-size:14px;}.title a{font:400 14px/1.5 Tahoma;}.example{margin-top:10px;}.example button{margin:0 5px 10px 0;}</style><script src="/3.5.1/build/yui/yui-min.js"></script><script>var config = {modules: {'price-calendar': {fullpath: 'price-calendar.js',type : 'js',requires: ['price-calendar-css']},'price-calendar-css': {fullpath: 'price-calendar.css',type : 'css'}}};YUI(config).use('price-calendar', 'jsonp', function(Y) {var sub = ng.sub;var url = '/learn/calendar/price-calendar/getData.asp?minDate={mindate}&maxDate={maxdate} &callback={callback}';//价格日历实例var oCal = new Y.PriceCalendar();//点击确定按钮oCal.on('confirm', function() {alert('入住时间:' + this.get('depDate') + '\n离店时间:' + this.get('endDate'));});//点击取消按钮oCal.on('cancel', function() {this.set('depDate', '').set('endDate', '').render();});Y.one('#J_Example').delegate('click', function(e) {var that = this,oTarget = e.currentTarget;switch(true) {//设置日历显示个数case oTarget.hasClass('J_Count'):this.set('count', oT arget.getAttribute('data-value')).render();break;//时间范围限定case oTarget.hasClass('J_Limit'):this.set('data', null).set('depDate', '').set('endDate', '').set('minDate', '').set('afterDays', oT arget.getAttribute('data-limit'));if(!oTarget.hasAttribute('data-date')) {this.set('date', new Date())}else {var oDate = oTarget.getAttribute('data-date');this.set('minDate', oDate);this.set('date', oDate);}oTarget.ancestor().one('.J_RoomStatus') ?oTarget.ancestor().one('.J_RoomStatus').setContent('\u663e\ u793a\u623f\u6001').removeClass('J_Show') :oTarget.ancestor().append('<buttonclass="J_RoomStatus">\u663e\u793a\u623f\u6001</button>');break;//异步拉取酒店数据case oTarget.hasClass('J_RoomStatus'):oTarget.toggleClass ('J_Show');if(oTarget.hasClass('J_Show'))Y.jsonp(sub(url, {mindate:this.get('minDate'),maxdate:this.get('maxDate')}),{on: {success: function(data) {that.set('data', data);oTarget.setContent('\u9690\u85cf\u623f\u6001')}}});else {this.set('data', null);oTarget.setContent('\u663e\u793a\u623f\u6001');}break;}}, 'button', oCal);});</script></head><body><h1 class="title">酒店价格日历Demo<em>(限定范围后可异步加载房态信息)</em><a href="api.html" target="_blank">API 文档</a></h1><div id="J_Example" class="example"><button class="J_Count" data-value="1">单日历</button> <button class="J_Count" data-value="2">双日历</button> <button class="J_Count" data-value="3">三日历</button> <br /><button class="J_Limit" data-limit="90">限定范围(今天->90天)</button><button class="J_Limit" data-limit="60" data-date="2012-10-01">指定日历时间并限定范围(2012年10月1号->60天)</button></div><div style="text-align:center;margin:50px 0; font:normal 14px/24px 'MicroSoft YaHei';"><p>适用浏览器:IE8、360、FireFox、Chrome、Safari、Opera、傲游、搜狗、世界之窗.</p><p>来源:<a href="/" target="_blank"> </a></p></div></body></html>。
基于javascript编写简洁日历_
基于javascript编写简洁日历_这篇文章主要介绍了基于javascript编写简洁日历的相关资料,需要的伴侣可以参考下一.表格行数问题既然要显示日期表格的话,首先得知道这个表格有多少行多少列,列数是已经确定的,从星期天(日历上第1列是星期天)到星期六一共7列。
要解决行数问题之前,还得先知道这个月的第1天是星期几,由于每个月的1号并不都是从日历上的星期天开头排的,可能1号是星期五,星期六也说不定,所以1号的左边部分,就得用空表格代替了。
那么用多少个空表格代替呢,这里就得用到getDay()方法了,该方法返回数组[0-6]中的一个数字,0代表星期天,1代表星期一,2代表星期二,以此类推。
所以假如一个月的1号是星期五的话,那么刚好左边需要5个空表格代替。
然后,假如一个月有31天,最终求出的表格行数就是:var tr_nums = Math.ceil((5 + 31)/7);当然,并不是每个月都是31天,所以我们得创建一个包含12个月份的数组,每个元素代表每个月份所包含的天数。
但是2月份比较特别,闰年的2月份有29天,平年的2月份只有28天。
所以,在创建数组之前,得自己创建一个推断闰年的函数://假如当前年份能被4整除但是不能被100整除或者能被400整除,即可确定为闰年,返回1,否则返回0function isLeap(year) {return year % 4 == 0 ? (year % 100 != 0 ? 1 : (year % 400 == 0 ? 1 : 0)) : 0;}然后我们创建一个月份数组:var days_per_month = new Array(31, 28 + isLeap(year), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);这样就能保证无论是平年还是闰年都会取出正确的天数,下面的代码用于猎取今日的相关信息:var today = new Date(), //猎取当前日期y = today.getFullYear(), //猎取日期中的年份m = today.getMonth(), //猎取日期中的月份(需要留意的是:月份是从0开头计算,猎取的值比正常月份的值少1)d = today.getDate(), //猎取日期中的日(便利在建立日期表格时高亮显示当天)firstday = new Date(y, m, 1), //猎取当月的第一天 dayOfWeek = firstday.getDay(), //推断第一天是星期几(返回[0-6]中的一个,0代表星期天,1代表星期一,以此类推)days_per_month = new Array(31, 28 + isLeap(y), 31,30, 31, 30, 31, 31, 30, 31, 30, 31), //创建月份数组所以最终就可以猎取当月所需表格的行数:var str_nums = Math.ceil((dayOfWeek + days_per_month[m]) / 7); //确定日期表格所需的行数二.打印日历表格表格本身是一个二维数组,所以让for大师出来跑两个循环就搞定啦,代码如下:for (i = 0; i str_nums; i += 1) { //第一层for循环创建tr标签document.write('tr');for (k = 0; k 7; k++) { //其次层for循环创建td 标签var idx = 7 * i + k; //为每个表格创建索引,从0开头var date = idx - dayOfWeek + 1; //将当月的1号与星期进行匹配//do something else}document.write('/tr');}三.附上完整的js日历代码script//推断当前年份是否是闰年(闰年2月份有29天,平年2月份只有28天)function isLeap(year) {return year % 4 == 0 ? (year % 100 != 0 ? 1 : (year % 400 == 0 ? 1 : 0)) : 0;}var i, k,today = new Date(), //猎取当前日期y = today.getFullYear(), //猎取日期中的年份 m = today.getMonth(), //猎取日期中的月份(需要留意的是:月份是从0开头计算,猎取的值比正常月份的值少1)d = today.getDate(), //猎取日期中的日(便利在建立日期表格时高亮显示当天)firstday = new Date(y, m, 1), //猎取当月的第一天dayOfWeek = firstday.getDay(), //推断第一天是星期几(返回[0-6]中的一个,0代表星期天,1代表星期一,以此类推)days_per_month = new Array(31, 28 + isLeap(y), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31), //创建月份数组str_nums = Math.ceil((dayOfWeek + days_per_month[m]) / 7); //确定日期表格所需的行数document.write("table cellspacing='0'trth日/thth 一/thth二/thth三/thth四/thth五/thth六/th/tr"); //打印表格第一行(显示星期)for (i = 0; i str_nums; i += 1) { //二维数组创建日期表格document.write('tr');for (k = 0; k 7; k++) {var idx = 7 * i + k; //为每个表格创建索引,从0开头var date = idx - dayOfWeek + 1; //将当月的1号与星期进行匹配(date = 0 || date days_per_month[m]) ? date = ' ': date = idx - dayOfWeek + 1; //索引小于等于0或者大于月份最大值就用空表格代替date == d ? document.write('td class="today"' + date + '/td') : document.write('td' + date + '/td'); //高亮显示当天}document.write('/tr');}document.write('/table');/scriptcss部分大家就自由发挥吧,当前时间是2021年5月2号,效果图如下:以上就是本文的全部内容,盼望对大家学习javascript 程序设计有所关心。
酒店协议代码
酒店协议代码下面是一个简单的酒店预订协议的代码,不过只有 250 字,没有达到 700 字的要求。
您可以根据需求添加更多细节。
```pythonclass HotelBookingAgreement:def __init__(self, guest_name, arrival_date, departure_date, room_type, num_guests):self.guest_name = guest_nameself.arrival_date = arrival_dateself.departure_date = departure_dateself.room_type = room_typeself.num_guests = num_guestsdef print_agreement(self):print("酒店预订协议")print("-------------")print(f"订房人:{self.guest_name}")print(f"到达日期:{self.arrival_date}")print(f"离开日期:{self.departure_date}")print(f"房型:{self.room_type}")print(f"客人人数:{self.num_guests}")def sign(self):print(f"{self.guest_name}已签署酒店预订协议。
")print("祝您入住愉快!")# 示例用法booking = HotelBookingAgreement("张三", "2022-01-01", "2022-01-05", "双人间", 2)booking.print_agreement()booking.sign()```以上代码定义了一个 `HotelBookingAgreement` 类,代表酒店预订协议。
javascript实现万年历代码
!DOCTYPE HTML PUBLIC -W3CDTD HTML 4.0 TransitionalENHTMLHEADTITLE在线万年历TITLEMETA http-equiv=content-type content=texthtml; charset=gb2312METAcontent=时间; JavaScript 日历;世界时间; 农历; 阳历; 阴历; 节日; 时区; 节气; 干支; 生肖; world time clock; gregorian solar; chinese lunar; calendar;name=keywordsMETA content=General name=RA TINGMETA content=ALL name=ROBOTSMETA content=1 name=REVISITMETA content=0 name=expiresMETA content=no-cache name=PragmaMETA content=no-cache name=Cache-ControlSCRIPT language=JScript!--个人偏好设定var conWeekend = 3; 周末颜色显示1=黑色, 2=绿色, 3=红色, 4=隔周休日期资料var lunarInfo=new Array(0x4bd8,0x4ae0,0xa570,0x54d5,0xd260,0xd950,0x5554,0x56af,0x9ad0,0x55d2,0x4ae0,0xa5b6,0xa4d0,0xd250,0xd255,0xb54f,0xd6a0,0xada2,0x95b0,0x4977,0x497f,0xa4b0,0xb4b5,0x6a50,0x6d40,0xab54,0x2b6f,0x9570,0x52f2,0x4970,0x6566,0xd4a0,0xea50,0x6a95,0x5adf,0x2b60,0x86e3,0x92ef,0xc8d7,0xc95f,0xd4a0,0xd8a6,0xb55f,0x56a0,0xa5b4,0x25df,0x92d0,0xd2b2,0xa950,0xb557,0x6ca0,0xb550,0x5355,0x4daf,0xa5b0,0x4573,0x52bf,0xa9a8,0xe950,0x6aa0,0xaea6,0xab50,0x4b60,0xaae4,0xa570,0x5260,0xf263,0xd950,0x5b57,0x56a0,0x96d0,0x4dd5,0x4ad0,0xa4d0,0xd4d4,0xd250,0xd558,0xb540,0xb6a0,0x95a6,0x95bf,0x49b0,0xa974,0xa4b0,0xb27a,0x6a50,0x6d40,0xaf46,0xab60,0x9570,0x4af5,0x4970,0x64b0,0x74a3,0xea50,0x6b58,0x5ac0,0xab60,0x96d5,0x92e0,0xc960,0xd954,0xd4a0,0xda50,0x7552,0x56a0,0xabb7,0x25d0,0x92d0,0xcab5,0xa950,0xb4a0,0xbaa4,0xad50,0x55d9,0x4ba0,0xa5b0,0x5176,0x52bf,0xa930,0x7954,0x6aa0,0xad50,0x5b52,0x4b60,0xa6e6,0xa4e0,0xd260,0xea65,0xd530,0x5aa0,0x76a3,0x96d0,0x4afb,0x4ad0,0xa4d0,0xd0b6,0xd25f,0xd520,0xdd45,0xb5a0,0x56d0,0x55b2,0x49b0,0xa577,0xa4b0,0xaa50,0xb255,0x6d2f,0xada0,0x4b63,0x937f,0x49f8,0x4970,0x64b0,0x68a6,0xea5f,0x6b20,0xa6c4,0xaaef,0x92e0,0xd2e3,0xc960,0xd557,0xd4a0,0xda50,0x5d55,0x56a0,0xa6d0,0x55d4,0x52d0,0xa9b8,0xa950,0xb4a0,0xb6a6,0xad50,0x55a0,0xaba4,0xa5b0,0x52b0,0xb273,0x6930,0x7337,0x6aa0,0xad50,0x4b55,0x4b6f,0xa570,0x54e4,0xd260,0xe968,0xd520,0xdaa0,0x6aa6,0x56df,0x4ae0,0xa9d4,0xa4d0,0xd150,0xf252,0xd520);var solarMonth=new Array(31,28,31,30,31,30,31,31,30,31,30,31);var Gan=new Array(甲,乙,丙,丁,戊,己,庚,辛,壬,癸);var Zhi=new Array(子,丑,寅,卯,辰,巳,午,未,申,酉,戌,亥);var Animals=new Array(鼠,牛,虎,兔,龙,蛇,马,羊,猴,鸡,狗,猪);var solarTerm = new Array(小寒,大寒,立春,雨水,惊蛰,春分,清明,谷雨,立夏,小满,芒种,夏至,小暑,大暑,立秋,处暑,白露,秋分,寒露,霜降,立冬,小雪,大雪,冬至);var sTermInfo = new Array(0,21208,42467,63836,85337,107014,128867,150921,173149,195551,218072,240693,2633 43,285989,308563,331033,353350,375494,397447,419210,440795,462224,483532,504758);var nStr1 = new Array('日','一','二','三','四','五','六','七','八','九','十');var nStr2 = new Array('初','十','廿','卅','□');var monthName = new Array(JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC);公历节日表示放假日var sFtv = new Array(0101新年元旦,0202 世界湿地日,0207 国际声援南非日,0210 国际气象节,0214 情人节,0301 国际海豹日,0303 全国爱耳日,0308 国际妇女节,0312 植树节孙中山逝世纪念日,0314 国际警察日,0315 国际消费者权益日,0317 中国国医节国际航海日,0321 世界森林日消除种族歧视国际日,0321 世界儿歌日,0322 世界水日,0323 世界气象日,0324 世界防治结核病日,0325 全国中小学生安全教育日,0330 巴勒斯坦国土日,0401 愚人节全国爱国卫生运动月(四月) 税收宣传月(四月),0407 世界卫生日,0422 世界地球日,0423 世界图书和版权日,0424 亚非新闻工作者日,0501 国际劳动节,0504 中国五四青年节,0505 碘缺乏病防治日,0508 世界红十字日,0512 国际护士节,0515 国际家庭日,0517 世界电信日,0518 国际博物馆日,0520 全国学生营养日,0523 国际牛奶日,0531 世界无烟日,0601 国际儿童节,0605 世界环境日,0606 全国爱眼日,0617 防治荒漠化和干旱日,0623 国际奥林匹克日,0625 全国土地日,0626 国际反毒品日,0701 中国共产党建党日世界建筑日,0702 国际体育记者日精品推介站()正式对外开放纪念日, 0707 中国人民抗日战争纪念日,0711 世界人口日,0730 非洲妇女日,0801 中国建军节,0808 中国男子节(爸爸节),0815 日本正式宣布无条件投降日,0908 国际扫盲日国际新闻工作者日,0910 教师节,0914 世界清洁地球日梅竹松生日^o^,0916 国际臭氧层保护日,0918 九·一八事变纪念日,0920 国际爱牙日,0927 世界旅游日,1001国庆节世界音乐日国际老人节,1001 国际音乐日,1002 国际和平与民主自由斗争日,1004 世界动物日,1008 全国高血压日,1008 世界视觉日,1009 世界邮政日万国邮联日,1010 辛亥革命纪念日世界精神卫生日,1013 世界保健日国际教师节,1014 世界标准日,1015 国际盲人节(白手杖节),1016 世界粮食日,1017 世界消除贫困日,1022 世界传统医药日,1024 联合国日世界发展信息日,1031 世界勤俭日,1107 十月社会主义革命纪念日,1108 中国记者日,1109 全国消防安全宣传教育日,1110 世界青年节,1111 国际科学与和平周(本日所属的一周),1112 孙中山诞辰纪念日,1114 世界糖尿病日,1117 国际大学生节世界学生节,1121 世界问候日世界电视日,1129 国际声援巴勒斯坦人民国际日,1201 世界艾滋病日,1203 世界残疾人日,1205 国际经济和社会发展志愿人员日,1208 国际儿童电视日,1209 世界足球日,1210 世界人权日,1212 西安事变纪念日,1213 南京大屠杀(1937年)纪念日!紧记血泪史!,1221 国际篮球日,1224 平安夜,1225 圣诞节,1229 国际生物多样性日);某月的第几个星期几。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>酒店入住离店js日历代码</title>
<style>
body{padding:0;margin:0 10px;}
.title{padding:0;margin:10px 0;font:700 18px/1.5 \5fae\8f6f\96c5\9ed1;}
.title em{font-style:normal;color:#C00;font-size:14px;}
.title a{font:400 14px/1.5 Tahoma;}
.example{margin-top:10px;}
.example button{margin:0 5px 10px 0;}
</style>
<script src="/3.5.1/build/yui/yui-min.js"></script>
<script>
var config = {
modules: {
'price-calendar': {
fullpath: 'price-calendar.js',
type : 'js',
requires: ['price-calendar-css']
},
'price-calendar-css': {
fullpath: 'price-calendar.css',
type : 'css'
}
}
};
YUI(config).use('price-calendar', 'jsonp', function(Y) {
var sub = ng.sub;
var url = '/learn/calendar/price-calendar/getData.asp?minDate={mindate}&m axDate={maxdate}&callback={callback}';
//价格日历实例
var oCal = new Y.PriceCalendar();
//点击确定按钮
oCal.on('confirm', function() {
alert('入住时间:' + this.get('depDate') + '\n离店时间:' + this.get('endDate'));
});
//点击取消按钮
oCal.on('cancel', function() {
this.set('depDate', '').set('endDate', '').render();
});
Y.one('#J_Example').delegate('click', function(e) {
var that = this,
oTarget = e.currentTarget;
switch(true) {
//设置日历显示个数
case oTarget.hasClass('J_Count'):
this.set('count', oTarget.getAttribute('data-value')).render();
break;
//时间范围限定
case oTarget.hasClass('J_Limit'):
this.set('data', null)
.set('depDate', '')
.set('endDate', '')
.set('minDate', '')
.set('afterDays', oTarget.getAttribute('data-limit'));
if(!oTarget.hasAttribute('data-date')) {
this.set('date', new Date())
}
else {
var oDate = oTarget.getAttribute('data-date');
this.set('minDate', oDate);
this.set('date', oDate);
}
oTarget.ancestor().one('.J_RoomStatus') ?
oTarget.ancestor().one('.J_RoomStatus').setContent('\u663e\u793a\u623f\u6001').removeClass(' J_Show') :
oTarget.ancestor().append('<button
class="J_RoomStatus">\u663e\u793a\u623f\u6001</button>');
break;
//异步拉取酒店数据
case oTarget.hasClass('J_RoomStatus'):
oTarget.toggleClass ('J_Show');
if(oTarget.hasClass('J_Show'))
Y.jsonp(
sub(url, {
mindate:this.get('minDate'),
maxdate:this.get('maxDate')
}),
{
on: {
success: function(data) {
that.set('data', data);
oTarget.setContent('\u9690\u85cf\u623f\u6001')
}
}
}
);
else {
this.set('data', null);
oTarget.setContent('\u663e\u793a\u623f\u6001');
}
break;
}
}, 'button', oCal);
});
</script>
</head>
<body>
<h1 class="title">酒店价格日历Demo<em>(限定范围后可异步加载房态信息)</em><a href="api.html" target="_blank">API文档</a></h1>
<div id="J_Example" class="example">
<button class="J_Count" data-value="1">单日历</button>
<button class="J_Count" data-value="2">双日历</button>
<button class="J_Count" data-value="3">三日历</button>
<br />
<button class="J_Limit" data-limit="90">限定范围(今天->90天)</button>
<button class="J_Limit" data-limit="60" data-date="2012-10-01">指定日历时间并限定范围(2012年10月1号->60天)</button>
</div>
<div style="text-align:center;margin:50px 0; font:normal 14px/24px 'MicroSoft YaHei';">
<p>适用浏览器:IE8、360、FireFox、Chrome、Safari、Opera、傲游、搜狗、世界之窗.</p> <p>来源:<a href="/" target="_blank"> </a></p>
</div>
</body>
</html>。