需求产生问题:本来想在网上找个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>

Python和JavaScript的主要区别在于类型系统和应用场景。1.Python使用动态类型,适合科学计算和数据分析。2.JavaScript采用弱类型,广泛用于前端和全栈开发。两者在异步编程和性能优化上各有优势,选择时应根据项目需求决定。

选择Python还是JavaScript取决于项目类型:1)数据科学和自动化任务选择Python;2)前端和全栈开发选择JavaScript。Python因其在数据处理和自动化方面的强大库而备受青睐,而JavaScript则因其在网页交互和全栈开发中的优势而不可或缺。

Python和JavaScript各有优势,选择取决于项目需求和个人偏好。1.Python易学,语法简洁,适用于数据科学和后端开发,但执行速度较慢。2.JavaScript在前端开发中无处不在,异步编程能力强,Node.js使其适用于全栈开发,但语法可能复杂且易出错。

javascriptisnotbuiltoncorc; saninterpretedlanguagethatrunsonenginesoftenwritteninc.1)javascriptwasdesignedAsalightweight,解释edganguageforwebbrowsers.2)Enginesevolvedfromsimpleterterterpretpreterterterpretertestojitcompilerers,典型地提示。

JavaScript可用于前端和后端开发。前端通过DOM操作增强用户体验,后端通过Node.js处理服务器任务。1.前端示例:改变网页文本内容。2.后端示例:创建Node.js服务器。

选择Python还是JavaScript应基于职业发展、学习曲线和生态系统:1)职业发展:Python适合数据科学和后端开发,JavaScript适合前端和全栈开发。2)学习曲线:Python语法简洁,适合初学者;JavaScript语法灵活。3)生态系统:Python有丰富的科学计算库,JavaScript有强大的前端框架。

JavaScript框架的强大之处在于简化开发、提升用户体验和应用性能。选择框架时应考虑:1.项目规模和复杂度,2.团队经验,3.生态系统和社区支持。

引言我知道你可能会觉得奇怪,JavaScript、C 和浏览器之间到底有什么关系?它们之间看似毫无关联,但实际上,它们在现代网络开发中扮演着非常重要的角色。今天我们就来深入探讨一下这三者之间的紧密联系。通过这篇文章,你将了解到JavaScript如何在浏览器中运行,C 在浏览器引擎中的作用,以及它们如何共同推动网页的渲染和交互。JavaScript与浏览器的关系我们都知道,JavaScript是前端开发的核心语言,它直接在浏览器中运行,让网页变得生动有趣。你是否曾经想过,为什么JavaScr


热AI工具

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

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

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

SublimeText3 Linux新版
SublimeText3 Linux最新版

WebStorm Mac版
好用的JavaScript开发工具

ZendStudio 13.5.1 Mac
功能强大的PHP集成开发环境

螳螂BT
Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

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