經常使用google的朋友一定對google絢麗的日曆控件記憶猶新吧,那我們也來實現一個,雖然功能和效果比不上,但重要的是實現的過程.
下面是要實現的html結構:
先說一下日曆查詢的演算法:
w=y parseInt(y/4) parseInt(c/4)-2*c parseInt(26*(m 1 )/10) d-1 ;
以下是詳細的說明過程,有興趣的可以去看下:
http://www.jb51.net/article/32572.htm
以下是實作的javascript程式碼:
複製程式碼 程式碼
sx.activex.calender={
bind:function(target){
var a=document.createElement("div");
var head=document.createElement("div");
var biaoti=document.createElement("div");
var select=document.createElement("select");
var yface=document.createElement("span");
var mface=document.createElement("span");
var body=document.createElement("div");
var select1=document.createElement("select");
yface.appendChild(select);
mface.appendChild(select1);
head.appendChild(yface);
head.appendChild(mface);
a.appendChild(head);
a.appendChild(biaoti);
a.appendChild(body);
yface.insertBefore(document.createTextNode("年"),yface.firstChild)
mface.insertBefore(document.createTextNode("月"),mface.firstChild)
a.style.position="絕對」;
biaoti.style.height="10%"
for(var i=0;ivar can=document.createElement("span")
can.style.width="14%";
can.style.height="100%";
can.style.textAlign="center";
biaoti.appendChild(can); }
biaoti.all[0].innerText="日"
biaoti.all[1].innerText="一"
biaoti.all[2].innerText="二"
biaoti .all[3].innerText="三"
biaoti.all[4].innerText="四"
biaoti.all[5].innerText="五"
biaoti.all [ 6] .innerText=“六”
head.style.height=“20%”
a.style.position=“絕對”
a.style.height=“200px”; >a.style.width ="302px";
a.style.border="1px 紅色實心";
yface.style.width="50%";
yface.style.padding=" 5px";
yface.style.height="100%";
select.style.width="80%";
for(var i=1960;ivar option=document. createElement("option");
選項.text=i;
select.add(選項)
}
mface.style.width="50%";
mface.style. padding="5px";
mface.style.height="100%";
select1.style.width="80%";
for(var i=1;ivar option=document.createElement("option");
選項.text=i;
select1.add(選項);
}
body.style.height="70%";
for(var i=0;ivar span=document.createElement("span");
span.style.width="14%";
span.style.height="16%";
span.style.textAlign="center";
span.onmouseover=function(){
this.style.cursor="hand";
this.tempcolor=this.style.backgroundColor;
this.style.backgroundColor="淺藍色";
}
span.onmouseout=function(){
this.style.backgroundColor=this.tempcolor;
}
span.onclick=function(){
target.value=select.options[select.selectedIndex].text "年" select1.options[select1.selectedIndex].text "月" 這。 insideText "日";
a.parentNode.removeChild(a);
}
body.appendChild(span);
}
select.onchange=function(){
for(var o in body.all){
body.all[o].innerText="";
if(o.toString()!="length")
body.all[o].style.backgroundColor="";
}
varyear1=this.options[this.selectedIndex].text;
var Month1=select1.options[select1.selectedIndex].text;
var y=parseInt(year1.substr(2,2)-0);
var c=parseInt(year1.substr(0,2));;
var m=parseInt(month1);;
m=m>=3?m:(y=y-1,m 12);
var d=1;
var w=y parseInt(y/4) parseInt(c/4)-2*c parseInt(26*(m 1)/10) d-1 ;
if(ww=w%7;
switch(parseInt(month1)){
情況2:
if(parseInt(year1)%4==0)
var r=29;
否則
var r=28;
var day=w;
for(var d=1;dbody.all[day ].innerText=d;
if(parseInt(year1)==(new Date()).getYear() && parseInt(month1)==(new Date()).getMonth() 1 && d==(new Date())。 getDate())
body.all[day-1].style.backgroundColor="red";
body.all[41].innerText="關閉";
}
休息;
預設值:
if(parseInt(month1)==1 || parseInt(month1)==3 || parseInt(month1)==5 || parseInt(month1)==7 || parseInt (month1)==8 || parseInt(month1)==10 || parseInt(month1)==12)
var r=31;
否則
var r=30;
var day=w;
for(var d=1;dbody.all[day ].innerText=d;
if(parseInt(year1)==(new Date()).getYear() && parseInt(month1)==(new Date()).getMonth() 1 && d==(new Date())。 getDate())
body.all[day-1].style.backgroundColor="red";
body.all[41].innerText="關閉";
}
休息;
}
}
select1.onchange=function(){
for(var o in body.all){
body.all[o] .innerText="";
if(o.toString()!="length")
body.all[o].style.backgroundColor="";
}
var Month1=this.options[this.selectedIndex].text;
varyear1=select.options[select.selectedIndex].text;
var y=parseInt(year1.substr(2,2)-0);
var c=parseInt(year1.substr(0,2));
var m=parseInt(month1);
m=m>=3?m:(y=y-1,m 12);
var d=1;
var w=y parseInt(y/4) parseInt(c/4)-2*c parseInt(26*(m 1)/10) d-1 ;
if(ww=w%7;
switch(parseInt(month1)){
情況2:
if(parseInt(year1)%4==0)
var r=29;
否則
var r=28;
var day=w;
for(var d=1;dbody.all[day ].innerText=d;
if(parseInt(year1)==(new Date()).getYear() && parseInt(month1)==(new Date()).getMonth() 1 && d==(new Date())。 getDate())
body.all[day-1].style.backgroundColor="red";
body.all[41].innerText="關閉";
}
休息;
預設值:
if(parseInt(month1)==1 || parseInt(month1)==3 || parseInt(month1)==5 || parseInt(month1)==7 || parseInt (month1)==8 || parseInt(month1)==10 || parseInt(month1)==12)
var r=31;
否則
var r=30;
var day=w;
for(var d=1;dbody.all[day ].innerText=d;
if(parseInt(year1)==(new Date()).getYear() && parseInt(month1)==(new Date()).getMonth() 1 && d==(new Date())。 getDate())
body.all[day-1].style.backgroundColor="red";
body.all[41].innerText="關閉";
}
休息;
}
}
var date=new Date();
for(var s1=0;s1
select.options[s1].selected=true;
休息;
}
}
for(var s2=0;s2
select1.options[s2].selected=true;
休息;
}
}
select.onchange();
for(var i in body.all){
if(body.all[i].innerText==date.getDate()){
body.all[i].style.backgroundColor="紅色的」;
}
}
target.onfocus=function(){
document.body.appendChild(a)
a.style.left=target.offsetLeft "px" ; ;
a.style.top=target.offsetTop target.offsetHeight "px"
}
target.onblur=function(){
if(a && window.event.clientY>a; . offsetTop && window.event.clientY
if(o. a) 返回;
a.parentNode.removeChild(a)
}
body.all[41].innerText="關閉"
body.all[41].onclick=function; () {
this.style.backgroundColor="";
a.parentNode.removeChild(a);
}
}
}
}
}
}
} 頭>
sx.activex.calender.bind(document.getElementById("a"));
腳本>
身體>

JavaScript在Web開發中的主要用途包括客戶端交互、表單驗證和異步通信。 1)通過DOM操作實現動態內容更新和用戶交互;2)在用戶提交數據前進行客戶端驗證,提高用戶體驗;3)通過AJAX技術實現與服務器的無刷新通信。

理解JavaScript引擎內部工作原理對開發者重要,因為它能幫助編寫更高效的代碼並理解性能瓶頸和優化策略。 1)引擎的工作流程包括解析、編譯和執行三個階段;2)執行過程中,引擎會進行動態優化,如內聯緩存和隱藏類;3)最佳實踐包括避免全局變量、優化循環、使用const和let,以及避免過度使用閉包。

Python更適合初學者,學習曲線平緩,語法簡潔;JavaScript適合前端開發,學習曲線較陡,語法靈活。 1.Python語法直觀,適用於數據科學和後端開發。 2.JavaScript靈活,廣泛用於前端和服務器端編程。

Python和JavaScript在社區、庫和資源方面的對比各有優劣。 1)Python社區友好,適合初學者,但前端開發資源不如JavaScript豐富。 2)Python在數據科學和機器學習庫方面強大,JavaScript則在前端開發庫和框架上更勝一籌。 3)兩者的學習資源都豐富,但Python適合從官方文檔開始,JavaScript則以MDNWebDocs為佳。選擇應基於項目需求和個人興趣。

從C/C 轉向JavaScript需要適應動態類型、垃圾回收和異步編程等特點。 1)C/C 是靜態類型語言,需手動管理內存,而JavaScript是動態類型,垃圾回收自動處理。 2)C/C 需編譯成機器碼,JavaScript則為解釋型語言。 3)JavaScript引入閉包、原型鍊和Promise等概念,增強了靈活性和異步編程能力。

不同JavaScript引擎在解析和執行JavaScript代碼時,效果會有所不同,因為每個引擎的實現原理和優化策略各有差異。 1.詞法分析:將源碼轉換為詞法單元。 2.語法分析:生成抽象語法樹。 3.優化和編譯:通過JIT編譯器生成機器碼。 4.執行:運行機器碼。 V8引擎通過即時編譯和隱藏類優化,SpiderMonkey使用類型推斷系統,導致在相同代碼上的性能表現不同。

JavaScript在現實世界中的應用包括服務器端編程、移動應用開發和物聯網控制:1.通過Node.js實現服務器端編程,適用於高並發請求處理。 2.通過ReactNative進行移動應用開發,支持跨平台部署。 3.通過Johnny-Five庫用於物聯網設備控制,適用於硬件交互。

我使用您的日常技術工具構建了功能性的多租戶SaaS應用程序(一個Edtech應用程序),您可以做同樣的事情。 首先,什麼是多租戶SaaS應用程序? 多租戶SaaS應用程序可讓您從唱歌中為多個客戶提供服務


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

MinGW - Minimalist GNU for Windows
這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

Dreamweaver CS6
視覺化網頁開發工具

WebStorm Mac版
好用的JavaScript開發工具

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境

記事本++7.3.1
好用且免費的程式碼編輯器