한국어
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http ://www.w3.org/1999/xhtml"> <head> <title> JS 日历downcodes.com </title> <meta name="author" content="建站school院"> <meta name="keywords" content="js日历,calender"> <meta name="description" content="js日历"> <script type="text/javascript"> function HS_DateAdd(interval,number,date){ number =parseInt(number); if (typeof(date)=="string"){var date = new Date(date.split("-")[0],date.split("-")[1],date.split("-" )[2])} if (typeof(date)=="object"){var date = date} switch(interval){ case "y":return new Date(date.getFullYear()+number,date.getMonth( ),date.getDate()); 부서지다; 케이스 "m": 새로운 Date(date.getFullYear(),date.getMonth()+number,checkDate(date.getFullYear(),date.getMonth()+number,date.getDate()))를 반환합니다. 부서지다; 케이스 "d": 새로운 Date(date.getFullYear(),date.getMonth(),date.getDate()+number)를 반환합니다. 부서지다; 케이스 "w": 새로운 Date(date.getFullYear(),date.getMonth(),7*number+date.getDate())를 반환합니다. 부서지다; } } function checkDate(연도, 월, 날짜){ var enddate = ["31","28","31","30","31","30","31","31","30 ","31","30","31"]; var returnDate = ""; if (year%4==0){enddate[1]="29"} if (date>enddate[month]){returnDate = enddate[month]}else{returnDate = date} return returnDate; } function WeekDay(날짜){ var theDate; if (typeof(date)=="string"){theDate = new Date(date.split("-")[0],date.split("-")[1],date.split("-") [2]);} if (typeof(date)=="object"){theDate = date} return theDate.getDay(); } 함수 HS_calender(){ var lis = ""; var 스타일 = ""; /*可以把下side css剪切去独立一个css文件downcodes.com*/ style +="<style type='text/css'>"; 스타일 +=".calender { 너비:170px; 높이:자동; 글꼴 크기:12px; 여백-오른쪽:14px; 배경:url(calenderbg.gif) 반복 없음 오른쪽 가운데 #fff; 테두리:1px 솔리드 #397EAE; 패딩:1px}"; style +=".calender ul {list-style-type:none; 여백:0; 패딩:0;}"; 스타일 +=".calender .day { 배경색:#EDF5FF; 높이:20px;}"; 스타일 +=".calender .day li,.calender .date li{ float:left; width:14%; height:20px; line-height:20px; text-align:center}"; style +=".calender li a { 텍스트 장식:없음; 글꼴-가족:Tahoma; 글꼴 크기:11px; 색상:#333}"; style +=".calender li a:hover { color:#f30; text-장식:underline}"; style +=".calender li a.hasArticle {font-weight:bold; color:#f60 !important}"; 스타일 +=".lastMonthDate, .nextMonthDate {color:#bbb;font-size:11px}"; style +=".selectThisYear a, .selectThisMonth a{text-decoration:none; margin:0 2px; color:#000;font-weight:bold}"; 스타일 +=".calender .LastMonth, .calender .NextMonth{ 텍스트 장식:없음; 색상:#000; 글꼴 크기:18px; 글꼴 무게:bold; 줄 높이:16px;}"; 스타일 +=".calender .LastMonth { float:left;}"; 스타일 +=".calender .NextMonth { float:right;}"; 스타일 +=".calenderBody {clear:both}"; 스타일 +=".calenderTitle {text-align:center;height:20px; line-height:20px;clear:both}"; style +=".today { background-color:#ffffaa;border:1px solid #f60; padding:2px}"; 스타일 +=".오늘 a { color:#f30; }"; style +=".calenderBottom {clear:both; border-top:1px solid #ddd; padding: 3px 0; text-align:left}"; 스타일 +=".calenderBottom a {텍스트 장식:없음; 여백:2px !important; 글꼴 무게:bold; 색상:#000}"; 스타일 +=".calenderBottom a.closeCalender{float:right}"; 스타일 +=".closeCalenderBox {float:right; border:1px solid #000; 배경:#fff; 글꼴 크기:9px; 너비:11px; 높이:11px; line-height:11px; text-align:center;overflow :숨김; 글꼴 무게:일반 !중요}"; 스타일 +="</style>"; 지금은 var; if (typeof(arguments[0])=="string"){ selectDate = 인수[0].split("-"); var 연도 = selectDate[0]; var 월 =parseInt(selectDate[1])-1+""; var 날짜 = selectDate[2]; now = new Date(년,월,일); }else if (typeof(arguments[0])=="object"){ 이제 = 인수[0]; } var lastMonthEndDate = HS_DateAdd("d","-1",now.getFullYear()+"-"+now.getMonth()+"-01").getDate(); var lastMonthDate = WeekDay(now.getFullYear()+"-"+now.getMonth()+"-01"); var thisMonthLastDate = HS_DateAdd("d","-1",now.getFullYear()+"-"+(parseInt(now.getMonth())+1).toString()+"-01"); var thisMonthEndDate = thisMonthLastDate.getDate(); var thisMonthEndDay = thisMonthLastDate.getDay(); var todayObj = 새로운 날짜(); today = todayObj.getFullYear()+"-"+todayObj.getMonth()+"-"+todayObj.getDate(); for (i=0; i<lastMonthDate; i++){ // 지난달 날짜 lis = "<li class='lastMonthDate'>"+lastMonthEndDate+"</li>" + lis; 지난월종료일--; } for (i=1; i<=thisMonthEndDate; i++){ // 이번 달 날짜 if(today == now.getFullYear()+"-"+now.getMonth()+"-"+i){ var todayString = now.getFullYear()+"-"+(parseInt(now.getMonth())+1).toString()+"-"+i; lis += "<li><a href=javascript:void(0) class='today' onclick='_selectThisDay(this)' title='"+now.getFullYear()+"-"+(parseInt(now. getMonth())+1)+"-"+i+"'>"+i+"</a></li>"; }else{ lis += "<li><a href=javascript:void(0) onclick='_selectThisDay(this)' title='"+now.getFullYear()+"-"+(parseInt(now.getMonth( ))+1)+"-"+i+"'>"+i+"</a></li>"; } } var j=1; for (i=thisMonthEndDay; i<6; i++){ // 다음 달 날짜 lis += "<li class='nextMonthDate'>"+j+"</li>"; j++; } lis += 스타일; var CalenderTitle = "<a href='javascript:void(0)' class='NextMonth' onclick=HS_calender(HS_DateAdd('m',1,'"+now.getFullYear()+"-"+now.getMonth( )+"-"+now.getDate()+"'),this) title='다음 달'>»</a>"; CalenderTitle += "<a href='javascript:void(0)' class='LastMonth' onclick=HS_calender(HS_DateAdd('m',-1,'"+now.getFullYear()+"-"+now.getMonth ()+"-"+now.getDate()+"'),this) title='지난 달'>«</a>"; CalenderTitle += "<span class='selectThisYear'><a href='javascript:void(0)' onclick='CalenderselectYear(this)' title='다른 연도를 선택하려면 여기를 클릭하세요' >"+now.getFullYear() +"</a></span>년<span class='selectThisMonth'><a href='javascript:void(0)' onclick='CalenderselectMonth(this)' title='다른 달을 선택하려면 여기를 클릭하세요'> "+(parseInt(now.getMonth())+1).toString()+"</a></span>월"; if (arguments.length>1){ 인수[1].parentNode.parentNode.getElementsByTagName("ul")[1].innerHTML = lis; 인수[1].parentNode.innerHTML = CalenderTitle; }else{ var CalenderBox = style+"<div class='calender'><div class='calenderTitle'>"+CalenderTitle+"</div><div class='calenderBody'><ul class='day'><li >일</li><li>일</li><li>이</li><li>삼</li><li>사</li><li>오</li><li>六</li></ul><ul class='date' id='thisMonthDate'>"+lis+"</ul></div><div class='calenderBottom'><a href='javascript:void( 0)' class='closeCalender' onclick='closeCalender(this)'>×</a><span><span><a href=javascript:void(0) onclick='_selectThisDay(this)' title=' "+todayString+"'>오늘</a></span></span></div></div>"; CalenderBox를 반환합니다. } } 함수 _selectThisDay(d){ var boxObj = d.parentNode.parentNode.parentNode.parentNode.parentNode; boxObj.targetObj.value = d.제목; boxObj.parentNode.removeChild(boxObj); } 함수 closeCalender(d){ var boxObj = d.parentNode.parentNode.parentNode; boxObj.parentNode.removeChild(boxObj); } function CalenderselectYear(obj){ var opt = ""; var thisYear = obj.innerHTML; for (i=1970; i<=2020; i++){ if (i==thisYear){ opt += "<option value="+i+" selected>"+i+"</option>"; }else{ opt += "<option value="+i+">"+i+"</option>"; } } opt = "<select onblur='selectThisYear(this)' onchange='selectThisYear(this)' style='font-size:11px'>"+opt+"</select>"; obj.parentNode.innerHTML = 선택; } 함수 selectThisYear(obj){ HS_calender(obj.value+"-"+obj.parentNode.parentNode.getElementsByTagName("span")[1].getElementsByTagName("a")[0].innerHTML+"-1",obj. 상위노드); } function CalenderselectMonth(obj){ var opt = ""; var thisMonth = obj.innerHTML; for (i=1; i<=12; i++){ if (i==thisMonth){ opt += "<option value="+i+" selected>"+i+"</option>"; }else{ opt += "<option value="+i+">"+i+"</option>"; } } opt = "<select onblur='selectThisMonth(this)' onchange='selectThisMonth(this)' style='font-size:11px'>"+opt+"</select>"; obj.parentNode.innerHTML = 선택; } 함수 selectThisMonth(obj){ HS_calender(obj.parentNode.parentNode.getElementsByTagName("span")[0].getElementsByTagName("a")[0].innerHTML+"-"+obj.value+"-1",obj. 상위노드); } function HS_setDate(inputObj){ var calenderObj = document.createElement("span"); calenderObj.innerHTML = HS_calender(새 날짜()); calenderObj.style.position = "절대"; calenderObj.targetObj = inputObj; inputObj.parentNode.insertBefore(calenderObj,inputObj.nextSibling); } </script> <style> body {font-size:12px} td {text-align:center} h1 {font-size:26px;} h4 {font-size:16px;} em {color:#999; 여백:0 10px; 글꼴 크기:11px; display:block} </style> </head> <body> <h1>날짜 선택기</h1> <h4 style="border-bottom:1px solid #ccc">ver:1.0</h4> <table border= 1 너비=400 높이=150> <tr> <td>文本文本文本</td> <td>点击输入框</td> <td>文本文本文本</td> </tr> <tr> <td >点击输入框</td> <td><input type="text" style="width:70px" onfocus="HS_setDate(this)">文本</td> <td>文本文本文本</td> < /tr> <tr> <td>文本文本文本</td> <td>点击输入框</td> <td>文本<input type="text" style="width:70px" onfocus="HS_setDate(this )">文本</td> </tr> </table> <ul> <li>不需要其他框架类库</li> <li>支持ie6、firefox、opera</li> <li>点击年份与月份可以下拉选择</li> </ul> </body> </html>