基于jquery實(shí)現(xiàn)日歷簽到功能
在一些任務(wù)游戲、貼吧管理中都會(huì)有一個(gè)簽到功能,幫助大家記錄登錄天數(shù),積累等級(jí)經(jīng)驗(yàn),這個(gè)日歷簽到功能是如何實(shí)現(xiàn)的,本文為大家進(jìn)行演。
本文實(shí)例講述了基于jquery實(shí)現(xiàn)日歷簽到功能。分享給大家供大家參考。具體如下:
運(yùn)行效果截圖如下:
具體代碼如下:
index.html
<!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>簽到效果實(shí)現(xiàn)</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script type="text/javascript" src="jquery-1.8.2.min.js"></script> <link rel="stylesheet" type="text/css" href="sign.css"/> <script type="text/javascript" src="calendar.js"></script> <script type="text/javascript"> $(function(){ //ajax獲取日歷json數(shù)據(jù) var signList=[{"signDay":"10"},{"signDay":"11"},{"signDay":"12"},{"signDay":"13"}]; calUtil.init(signList); }); </script> </head> <body> <div style="width:300px;height:300px;" id="calendar"></div> </body> </html>
sign.css
.singer_r_img{display:block;width:114px;height:52px;line-height:45px;background:url(images/sing_week.gif) right 2px no-repeat;vertical-align:middle;*margin-bottom:-10px;text-decoration:none;} .singer_r_img:hover{background-position:right -53px;text-decoration:none;} .singer_r_img span{margin-left:14px;font-size:16px;font-family:'Hiragino Sans GB','Microsoft YaHei',sans-serif !important;font-weight:700;color:#165379;} .singer_r_img.current{background:url(images/sing_sing.gif) no-repeat 0 2px;border:0;text-decoration:none;} .sign table{border-collapse: collapse;border-spacing: 0;width:100%;} .sign th,.sign td {width: 30px;height: 40px;text-align: center;line-height: 40px;border:1px solid #e3e3e3;} .sign th {font-size: 16px;} .sign td {color: #404040;vertical-align: middle;} .sign .on {background-color:red;} .calendar_month_next,.calendar_month_prev{width: 34px;height: 40px;cursor: pointer;background:url(images/sign_arrow.png) no-repeat;} .calendar_month_next {float: right;background-position:-42px -6px;} .calendar_month_span {display: inline;line-height: 40px;font-size: 16px;color: #656565;letter-spacing: 2px;font-weight: bold;} .calendar_month_prev {float: left;background-position:-5px -6px;} .sign_succ_calendar_title {text-align: center;width:398px;border-left:1px solid #e3e3e3;border-right:1px solid #e3e3e3;background:#fff;} .sign_main {width: 400px;border-top:1px solid #e3e3e3;font-family: "Microsoft YaHei",SimHei;}
calendar.js
var calUtil = { //當(dāng)前日歷顯示的年份 showYear:2015, //當(dāng)前日歷顯示的月份 showMonth:1, //當(dāng)前日歷顯示的天數(shù) showDays:1, eventName:"load", //初始化日歷 init:function(signList){ calUtil.setMonthAndDay(); calUtil.draw(signList); calUtil.bindEnvent(); }, draw:function(signList){ //綁定日歷 var str = calUtil.drawCal(calUtil.showYear,calUtil.showMonth,signList); $("#calendar").html(str); //綁定日歷表頭 var calendarName=calUtil.showYear+"年"+calUtil.showMonth+"月"; $(".calendar_month_span").html(calendarName); }, //綁定事件 bindEnvent:function(){ //綁定上個(gè)月事件 $(".calendar_month_prev").click(function(){ //ajax獲取日歷json數(shù)據(jù) var signList=[{"signDay":"10"},{"signDay":"11"},{"signDay":"12"},{"signDay":"13"}]; calUtil.eventName="prev"; calUtil.init(signList); }); //綁定下個(gè)月事件 $(".calendar_month_next").click(function(){ //ajax獲取日歷json數(shù)據(jù) var signList=[{"signDay":"10"},{"signDay":"11"},{"signDay":"12"},{"signDay":"13"}]; calUtil.eventName="next"; calUtil.init(signList); }); }, //獲取當(dāng)前選擇的年月 setMonthAndDay:function(){ switch(calUtil.eventName) { case "load": var current = new Date(); calUtil.showYear=current.getFullYear(); calUtil.showMonth=current.getMonth() + 1; break; case "prev": var nowMonth=$(".calendar_month_span").html().split("年")[1].split("月")[0]; calUtil.showMonth=parseInt(nowMonth)-1; if(calUtil.showMonth==0) { calUtil.showMonth=12; calUtil.showYear-=1; } break; case "next": var nowMonth=$(".calendar_month_span").html().split("年")[1].split("月")[0]; calUtil.showMonth=parseInt(nowMonth)+1; if(calUtil.showMonth==13) { calUtil.showMonth=1; calUtil.showYear+=1; } break; } }, getDaysInmonth : function(iMonth, iYear){ var dPrevDate = new Date(iYear, iMonth, 0); return dPrevDate.getDate(); }, bulidCal : function(iYear, iMonth) { var aMonth = new Array(); aMonth[0] = new Array(7); aMonth[1] = new Array(7); aMonth[2] = new Array(7); aMonth[3] = new Array(7); aMonth[4] = new Array(7); aMonth[5] = new Array(7); aMonth[6] = new Array(7); var dCalDate = new Date(iYear, iMonth - 1, 1); var iDayOfFirst = dCalDate.getDay(); var iDaysInMonth = calUtil.getDaysInmonth(iMonth, iYear); var iVarDate = 1; var d, w; aMonth[0][0] = "日"; aMonth[0][1] = "一"; aMonth[0][2] = "二"; aMonth[0][3] = "三"; aMonth[0][4] = "四"; aMonth[0][5] = "五"; aMonth[0][6] = "六"; for (d = iDayOfFirst; d < 7; d++) { aMonth[1][d] = iVarDate; iVarDate++; } for (w = 2; w < 7; w++) { for (d = 0; d < 7; d++) { if (iVarDate <= iDaysInMonth) { aMonth[w][d] = iVarDate; iVarDate++; } } } return aMonth; }, ifHasSigned : function(signList,day){ var signed = false; $.each(signList,function(index,item){ if(item.signDay == day) { signed = true; return false; } }); return signed ; }, drawCal : function(iYear, iMonth ,signList) { var myMonth = calUtil.bulidCal(iYear, iMonth); var htmls = new Array(); htmls.push("<div class='sign_main' id='sign_layer'>"); htmls.push("<div class='sign_succ_calendar_title'>"); htmls.push("<div class='calendar_month_next'>下月</div>"); htmls.push("<div class='calendar_month_prev'>上月</div>"); htmls.push("<div class='calendar_month_span'></div>"); htmls.push("</div>"); htmls.push("<div class='sign' id='sign_cal'>"); htmls.push("<table>"); htmls.push("<tr>"); htmls.push("<th>" + myMonth[0][0] + "</th>"); htmls.push("<th>" + myMonth[0][1] + "</th>"); htmls.push("<th>" + myMonth[0][2] + "</th>"); htmls.push("<th>" + myMonth[0][3] + "</th>"); htmls.push("<th>" + myMonth[0][4] + "</th>"); htmls.push("<th>" + myMonth[0][5] + "</th>"); htmls.push("<th>" + myMonth[0][6] + "</th>"); htmls.push("</tr>"); var d, w; for (w = 1; w < 7; w++) { htmls.push("<tr>"); for (d = 0; d < 7; d++) { var ifHasSigned = calUtil.ifHasSigned(signList,myMonth[w][d]); console.log(ifHasSigned); if(ifHasSigned){ htmls.push("<td class='on'>" + (!isNaN(myMonth[w][d]) ? myMonth[w][d] : " ") + "</td>"); } else { htmls.push("<td>" + (!isNaN(myMonth[w][d]) ? myMonth[w][d] : " ") + "</td>"); } } htmls.push("</tr>"); } htmls.push("</table>"); htmls.push("</div>"); htmls.push("</div>"); return htmls.join(''); } };
希望本文所述對(duì)大家學(xué)習(xí)javascript程序設(shè)計(jì)有所幫助。
- Bootstrap 時(shí)間日歷插件bootstrap-datetimepicker配置與應(yīng)用小結(jié)
- bootstrap中日歷范圍選擇插件daterangepicker的使用詳解
- BootStrap的雙日歷時(shí)間控件使用
- bootstrap daterangepicker雙日歷時(shí)間段選擇控件詳解
- BootStrap daterangepicker 雙日歷控件
- Bootstrap DateTime Picker日歷控件簡(jiǎn)單應(yīng)用
- bootstrap日歷插件datetimepicker使用方法
- jQuery EasyUI API 中文文檔 - Calendar日歷使用
- 為開(kāi)發(fā)者準(zhǔn)備的10款最好的jQuery日歷插件
- Bootstrap+Jquery實(shí)現(xiàn)日歷效果
相關(guān)文章
jQuery實(shí)現(xiàn) 注冊(cè)時(shí)選擇閱讀條款 左右移動(dòng)
本篇文章,小編將為大家介紹jQuery實(shí)現(xiàn) 注冊(cè)時(shí)選擇閱讀條款 左右移動(dòng),有需要的朋友可以參考一下2013-04-04基于jquery實(shí)現(xiàn)發(fā)送文章到手機(jī)的代碼
這篇文章主要介紹了基于jquery實(shí)現(xiàn)發(fā)送文章到手機(jī)的代碼,非常簡(jiǎn)單實(shí)用,需要的朋友可以參考下2014-12-12增強(qiáng)用戶體驗(yàn)友好性之jquery easyui window 窗口關(guān)閉時(shí)的提示
在項(xiàng)目中,客戶提出這么個(gè)要求,就是在關(guān)閉彈出的窗口的時(shí)候,如果點(diǎn)擊 紅X 或 取消按鈕 則提示 ”確認(rèn)保存了當(dāng)前的操作“ 這么個(gè)信息,否則就不提示啦2012-06-06jquery.simple.tree插件 更簡(jiǎn)單,兼容性更好的無(wú)限樹(shù)插件
在這里介紹一款小巧,功能強(qiáng)大,能拖拽,支持異步,且兼容性更高的jquery Tree插件2010-09-09內(nèi)容滑動(dòng)切換效果jquery.hwSlide.js插件封裝
這篇文章主要為大家詳細(xì)介紹了jQuery開(kāi)發(fā)之內(nèi)容滑動(dòng)切換效果的相關(guān)資料,jquery.hwSlide.js插件進(jìn)行封裝具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-07-07jQuery 全選 全不選 事件綁定的實(shí)現(xiàn)代碼
本文給大家分享一段代碼基于jQuery 全選 全不選 事件綁定的實(shí)現(xiàn)方法,代碼簡(jiǎn)單易懂,非常不錯(cuò),需要的朋友參考下2017-01-01淺談jQuery頁(yè)面的滾動(dòng)位置scrollTop、scrollLeft
官方文檔的解釋有點(diǎn)含糊,其實(shí)換個(gè)角度就很容易理解了,scrollTop獲取的是內(nèi)部元素超出外部容器的高度。 例如:$('window').scrollTop()獲取的就是當(dāng)前這個(gè)頁(yè)面超出窗口最上端的高度,scrollLeft與此同理2015-05-05jquery的attr方法禁用表單元素禁用輸入內(nèi)容
這篇文章主要介紹了通過(guò)jquery的attr方法來(lái)禁用表單元素禁輸入內(nèi)容,示例如下,需要的朋友可以參考參考2014-06-06