js日历功能对象_javascript技巧
需求产生问题:本来想在网上找个js代码,可是发现要么太复杂,要么不好控制,要么兼容性不好......
问题分析: 发现不是优秀的就是最好的.... 适合自己的就是最好的。
问题解决: 决定自己写一个日历 功能。
代码呈现:
日历主程序
var calendar={
STR:function(){with(this.data)return ""+Y+"年,"+M+"月,"+D+"号,星期"+WN[W];},
V:function(o,spli,sx){with(this)return o[sx]=""+data.Y+spli+data.M+spli+data.D},
T:function(){with(this)return data.TABLE},
dnY:function(){with(this){calendarChange(data.Y+1,data.M-1,data.D)}},
dnM:function(){with(this){calendarChange(data.Y,data.M,data.D)}},
upY:function(){with(this){calendarChange(data.Y-1,data.M-1,data.D)}},
upM:function(){with(this){calendarChange(data.Y,data.M-2,data.D)}},
day:function(o){with(this){data.D=o;calendarChange(data.Y,data.M-1,data.D)}},
data:{Y:null,M:null,D:null,W:null,H:null,U:null,YMD:null,YMD_C:"hot",ARR:null,TABLE:null,MN:null,WN:null,SELECT:null,TADAY:new Date(),TADAY_C:"taday",ROWLEN:7,VALUE:null},
creatTable:function(){with(this){
var table="
"+showText+" | ";
data.TABLE=table;return table;
}},
calendarStarArr:function(userY,userM,userD){with(this){
var Arr=[];
var now = new Date(userY,userM,userD);
var LastDay = now.getLastDay();
var FirstDayofWeek = now.FirstDayofWeek();
data.YMD=now;data.Y=now.getFullYear();
data.M=now.getMonth()+1;data.D=now.getDate();data.W=now.getDay();
while(Arr.length!=FirstDayofWeek){Arr.push(false)}
for(var i=0;i
data.ARR=Arr;return Arr;
}},
calendarChange:function(userY,userM,userD){with(this){
calendarStarArr(userY,userM,userD);creatTable()
}},
calendarStar:function(userY,userM,userD){with(this){
data.MN = ["零","一","二","三","四","五","六","七","八","九","十","十一","十二"];
data.WN = ["日","一","二","三","四","五","六"];
calendarChange(userY,userM,userD);
}},
init:function(){with(this){
Date.prototype.getLastDay=function(){return(new Date(this.getFullYear(),this.getMonth()+1,0).getDate())}
Date.prototype.FirstDayofWeek=function(){return(new Date(this.getFullYear(),this.getMonth(),1).getDay())}
calendarStar(new Date().getFullYear(),new Date().getMonth(),new Date().getDate())
}}
}
代码应用讲解:
var aa=new calendar()//创建一个新日历
aa.init()//日历初始
obj.innerHTML=aa.STR()//显示日期字符串
obj.innerHTML=aa.T()//显示表格
aa.dnY()//下一年
aa.upY()//上一年
aa.dnM()//下一月
aa.upM()//上一月
aa.day(Number)//改变日历显示的几号(Number 需要传一个数值型参数)
这个日历对象实现的是日历的核心功能功能,
具体是日历放在哪里,
哪个事件触发哪个函数这个我没有写,
要是那样的话就失去我写这个日历的原有目的了。
怎么大家都没反应,我弄个例子,大家看下吧
<script> <BR>var calendar={ <BR>STR:function(){with(this.data)return ""+Y+"年,"+M+"月,"+D+"号,星期"+WN[W];}, <BR>V:function(spli){with(this)return ""+data.Y+spli+data.M+spli+data.D}, <BR>T:function(){with(this)return data.TABLE}, <BR>dnY:function(){with(this){calendarChange(data.Y+1,data.M-1,data.D)}}, <BR>dnM:function(){with(this){calendarChange(data.Y,data.M,data.D)}}, <BR>upY:function(){with(this){calendarChange(data.Y-1,data.M-1,data.D)}}, <BR>upM:function(){with(this){calendarChange(data.Y,data.M-2,data.D)}}, <BR>day:function(o){with(this){data.D=o;calendarChange(data.Y,data.M-1,data.D)}}, <BR>data:{Y:null,M:null,D:null,W:null,H:null,U:null,YMD:null,YMD_C:"hot",ARR:null,TABLE:null,MN:null,WN:null,SELECT:null,TADAY:new Date(),TADAY_C:"taday",ROWLEN:7,VALUE:null}, <BR>creatTable:function(){with(this){ <BR>var table="<table height=100% width=100%><tr>" <BR>for(var i=0;i<data.ROWLEN;i++){var t=data.WN[i]||" ";table+="<th>"+t+"";} <BR>for(var i in data.ARR){var showText=data.ARR[i]||" ",br=i%data.ROWLEN,title,css=""; <BR>if(!br){table+="<tr>"}; <BR>data.ARR[i]?title=data.Y+"-"+data.M+"-"+showText:title=""; <BR>if(String(data.D)==String(data.ARR[i])){css+=" "+data.YMD_C;} <BR>if(data.YMD.getFullYear()==data.TADAY.getFullYear()&&data.YMD.getMonth()==data.TADAY.getMonth()&&String(data.TADAY.getDate())==String(data.ARR[i])){css=" "+data.TADAY_C} <BR>table+="<td title='"+title+"' class="+css+">"+showText+""; <BR>}table+="" <BR>data.TABLE=table;return table; <BR>}}, <BR>calendarStarArr:function(userY,userM,userD){with(this){ <BR>var Arr=[]; <BR>var now = new Date(userY,userM,userD); <BR>var LastDay = now.getLastDay(); <BR>var FirstDayofWeek = now.FirstDayofWeek(); <BR>data.YMD=now;data.Y=now.getFullYear(); <BR>data.M=now.getMonth()+1;data.D=now.getDate();data.W=now.getDay(); <BR>while(Arr.length!=FirstDayofWeek){Arr.push(false)} <BR>for(var i=0;i<LastDay;i++){Arr.push(i+1)} <BR>while(Arr.length%data.ROWLEN!=0){Arr.push(false)} <BR>data.ARR=Arr;return Arr; <BR>}}, <BR>calendarChange:function(userY,userM,userD){with(this){ <BR>calendarStarArr(userY,userM,userD);creatTable() <BR>}}, <BR>calendarStar:function(userY,userM,userD){with(this){ <BR>data.MN = ["零","一","二","三","四","五","六","七","八","九","十","十一","十二"]; <BR>data.WN = ["日","一","二","三","四","五","六"]; <BR>calendarChange(userY,userM,userD); <BR>}}, <BR>init:function(){with(this){ <BR>Date.prototype.getLastDay=function(){return(new Date(this.getFullYear(),this.getMonth()+1,0).getDate())} <BR>Date.prototype.FirstDayofWeek=function(){return(new Date(this.getFullYear(),this.getMonth(),1).getDay())} <BR>calendarStar(new Date().getFullYear(),new Date().getMonth(),new Date().getDate()) <BR>}} <BR>} <BR></script>
| |||
<script> <BR>calendar.init() <BR>function calendarChange(){ <BR>var calendar_body=document.getElementById("calendar_body") <BR>calendar_body.innerHTML=calendar.T()//显示表格 <BR>var calendar_str=document.getElementById("calendar_str") <BR>calendar_str.innerHTML=calendar.STR()//显示日期字符串 <BR>calendarControl()//调用日历控制 <BR>} <BR>calendarChange()//日历更新 <BR>function calendarControl(){ <BR>var calendar_str=document.getElementById("calendar_str") <BR>calendar_str.onclick=function(){ calendar.init();calendarChange()}//返回今天功能实现 <BR>var calendar_dnY=document.getElementById("calendar_dnY") <BR>calendar_dnY.onclick=function(){ calendar.dnY();calendarChange()}//下一年 功能实现 <BR>var calendar_dnM=document.getElementById("calendar_dnM") <BR>calendar_dnM.onclick=function(){ calendar.dnM();calendarChange()}//下一月 功能实现 <BR>var calendar_upY=document.getElementById("calendar_upY") <BR>calendar_upY.onclick=function(){ calendar.upY();calendarChange()}//上一年 功能实现 <BR>var calendar_upM=document.getElementById("calendar_upM") <BR>calendar_upM.onclick=function(){ calendar.upM();calendarChange()}//上一月 功能实现 <BR>var calendar_day=document.getElementById("calendar_body").getElementsByTagName("td"); <BR>for(var i in calendar_day){calendar_day[i].onclick=function(){var N=Number(this.innerText);if(N){calendar.day(N);calendarChange()}}}//当天日期 功能实现 <BR>} <BR></script>

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

在Windows11中组织日常工作和例行公事的一项重要工具是在任务栏中显示时间和日期。此功能通常位于屏幕的右下角,可让您即时访问时间和日期。通过单击此区域,您可以调出日历,从而更轻松地检查即将到来的约会和日期,而无需打开单独的应用程序。但是,如果您使用多个显示器,则此功能可能会遇到问题。具体来说,虽然时钟和日期显示在所有连接的显示器上的任务栏上,但单击第二个显示器上的日期和时间来显示日历的功能不可用。截至目前,此功能仅在主显示屏上起作用-它与Windows10不同,在Windows10中,单击任

很多用户们想要通过win10日历这个工具来查看当前天数,但是日历不会自动显示这一功能,其实我们只需要通过简单的设置,就能够看到今年的累计周数了哦~win10日历显示周数设置教程:1、在桌面左下角的搜索中输入日历并且打开应用。2、在打开的日历应用中,点击左下角的“齿轮”图标后,会在右侧弹出设置,我们点击“日历设置”3、继续在打开的日历设置中,找到“周数”然后将周数选项调整到“一年中的第一天”即可。4、在完成以上设置后,点击“周”即可看到今年的周数统计了。

如果您的Outlook日历无法与Google日历、Teams、iPhone、Android、Zoom、Office帐户等同步,请执行以下步骤来解决问题。日历应用程序可以连接到其他日历服务,如谷歌日历、iPhone、安卓、微软Office365等,这是非常有用的,因为它可以自动同步。但如果OutlookCalendar无法与第三方日历同步怎么办?可能的原因可能是选择错误的日历进行同步,日历不可见,后台应用程序干扰,过时的Outlook应用程序或日历应用程序,等等。修复Outlook日历不同步的初步

日历可以帮助用户们记录下你的行程,甚至还可以设置提醒,但是也有不少的用户们在询问win10日历事件提醒不弹出怎么办?用户们可以先检查一下windows更新情况或者是清除windows应用商店缓存来进行操作就可以了。下面就让本站来为用户们来仔细的介绍一下win10日历事件提醒不弹出问题解析吧。添加日历事件在系统菜单中点击“日历”程序。鼠标左键点击日历中的日期。在编辑窗口输入事件名称和提醒时间,点击“保存”按钮即可添加事件了。win10日历事件提醒不弹出问题解决

无期迷途采购办确定将于2月28日上午11点更新,玩家可以前往淘宝搜索无期迷途采购办选择店铺分类进行购买,本次为大家带来的是MBCC生日会系列及2024台历周边,一起来看看本次的商品详情。无期迷途采购办:日历和生日系列周边上新!无期迷途采购办上新!—预售时间:2024年2月28日11:00——2024年3月13日23:59采购地址:淘宝搜索【无期迷途采购办】选择【店铺】分类即可进店采购;周边介绍:本次周边上新为MBCC生日会系列及2024台历周边,请点击长图查阅详情。采购办上新周边介绍—MBCC生

有使用win0系统的小伙伴有遇见win10日历打不开的情况,这个是正常的电脑的小故障而已,在win10系统的隐私设置里可以解决,今天小编带来了详细的解决方法,下面大家一起来看看吧。win10右下角的日历打不开解决方法1、在win10系统中点击开始→点击上方的程序列表按钮→往下找到拼音(中文)R→日历2、初次使用,可能新事件会点不开(鼠标靠上去,不会有选中的深蓝色),可以在隐私中设置一下。点击桌面左上方的三道杠图标→底部就会有设置菜单;3、在弹出的界面中点击隐私;4、如果之前使用过设置,可以点击左

如果您的Windows11计算机显示时间错误,可能会导致很多问题,甚至阻止您连接到互联网。事实上,当系统显示不正确的日期和时间时,某些应用程序会拒绝打开或运行。那么应该如何解决这个问题呢?下面一起来看看吧!方法一:1、我们首先右键点击下方任务栏空白处,选择任务栏设置2、在任务栏设置中找到右侧的taskbarcorneroverflow3、然后在它上方找到clock或时钟选择开启即可。方法二:1、按下键盘快捷键win+r调出运行,输入regedit回车确定。2、打开注册表编辑器,在其中找到HKEY

Vue是一款非常流行的前端框架,它提供了很多工具和功能,如组件化、数据绑定、事件处理等,能够帮助开发者构建出高效、灵活和易维护的Web应用程序。在这篇文章中,我来介绍如何使用Vue实现一个日历组件。1、需求分析首先,我们需要分析一下这个日历组件的需求。一个基本的日历应该具备以下功能:展示当前月份的日历页面;支持切换到前一月或下一月;支持点击某一天,
