javascript實作日曆控制項(年月日關閉按鈕)_javascript技巧
經常使用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"));
腳本>
身體>

熱AI工具

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

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

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

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

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

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

JavaScript是現代Web開發的基石,它的主要功能包括事件驅動編程、動態內容生成和異步編程。 1)事件驅動編程允許網頁根據用戶操作動態變化。 2)動態內容生成使得頁面內容可以根據條件調整。 3)異步編程確保用戶界面不被阻塞。 JavaScript廣泛應用於網頁交互、單頁面應用和服務器端開發,極大地提升了用戶體驗和跨平台開發的靈活性。

Python和JavaScript開發者的薪資沒有絕對的高低,具體取決於技能和行業需求。 1.Python在數據科學和機器學習領域可能薪資更高。 2.JavaScript在前端和全棧開發中需求大,薪資也可觀。 3.影響因素包括經驗、地理位置、公司規模和特定技能。

如何在JavaScript中將具有相同ID的數組元素合併到一個對像中?在處理數據時,我們常常會遇到需要將具有相同ID�...

學習JavaScript不難,但有挑戰。 1)理解基礎概念如變量、數據類型、函數等。 2)掌握異步編程,通過事件循環實現。 3)使用DOM操作和Promise處理異步請求。 4)避免常見錯誤,使用調試技巧。 5)優化性能,遵循最佳實踐。

實現視差滾動和元素動畫效果的探討本文將探討如何實現類似資生堂官網(https://www.shiseido.co.jp/sb/wonderland/)中�...

JavaScript的最新趨勢包括TypeScript的崛起、現代框架和庫的流行以及WebAssembly的應用。未來前景涵蓋更強大的類型系統、服務器端JavaScript的發展、人工智能和機器學習的擴展以及物聯網和邊緣計算的潛力。

深入探討console.log輸出差異的根源本文將分析一段代碼中console.log函數輸出結果的差異,並解釋其背後的原因。 �...
