Implementation of Calendar Check-in function based on jquery _jquery

Source: Internet
Author: User

In some task games, post Bar management will have a check-in function, to help you record the number of days to log in, accumulated level of experience, this calendar check-in function is how to achieve, this article for everyone to play.

The example of this article describes the implementation of the calendar Check-in function based on jquery. Share to everyone for your reference. Specifically as follows:
The screenshot of the running effect is as follows:

The specific code is as follows:

Index.html

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
 
 

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 = {//Current calendar display year showyear:2015,//Current calendar display month showmonth:1,//number of days displayed in current calendar showdays:1, EventName: "Load
    ",///Initialize calendar init:function (signlist) {calutil.setmonthandday ();
    Calutil.draw (signlist);
  Calutil.bindenvent ();
    }, Draw:function (signlist) {//bind calendar var str = calutil.drawcal (calutil.showyear,calutil.showmonth,signlist);
    $ ("#calendar"). html (str);
    Binding Calendar Header var calendarname=calutil.showyear+ "year" +calutil.showmonth+ "month";  
  $ (". Calendar_month_span"). HTML (calendarname);
      },//Bind event Bindenvent:function () {//Bind last month Event $ (". Calendar_month_prev"). Click (function () {//ajax get calendar JSON data
      var signlist=[{"Signday": "Ten"},{"Signday": "One"},{"Signday": "One"},{"Signday": "13"};
      Calutil.eventname= "Prev";
    Calutil.init (signlist);
    }); Bind next month Event $ (". Calendar_month_next"). Click (function () {//ajax get calendar JSON data var signlist=[{"Signday": "},{" si
      Gnday ":" One "},{" Signday ":"},{"Signday": "13"}]; Calutil.evEntname= "Next";
    Calutil.init (signlist);
  });  ///Get the currently selected year 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 ("Year") [1].split ("month") [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 ("Year") [1].split ("month") [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] = "Day";
   AMONTH[0][1] = "one";
   AMONTH[0][2] = "two";
   AMONTH[0][3] = "three";
   AMONTH[0][4] = "four";
   AMONTH[0][5] = "five";
   AMONTH[0][6] = "six";
    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 ' > next month </div>");
   Htmls.push ("<div class= ' Calendar_month_prev ' > Last month </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 ("); }
};

Hopefully this article will help you learn about JavaScript programming.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.