Rewritten HTML5 Hotel Check-in date Select Calendar Plugin

Source: Internet
Author: User

<! DOCTYPE html>
<title> Contact Angle Tester </title>
<script src= "Http://www.codefans.net/ajaxjs/jquery-1.6.2.min.js" type= "Application/javascript" language= " JavaScript "></script>
<style>
*{margin:0; padding:0;}
. choosecal{width:96%; margin:3% auto; overflow:hidden;}
. ccaltop{width:99%; border-radius:5px; border:1px solid #000;}
. caltline1,.caltline2{width:94%; Background-color: #F90; overflow:hidden; padding:2% 3%;}
. caltline1 p,.caltline2 p{float:left; width:10%; font-weight:700; text-align:right;}
. caltline1. bookdate{width:90%; text-align:left;}
. caltline2{Background-color: #FFF; display:none;}
. Caltline2 p{width:20%;}
. caltline2. datetext{width:35%; border:1px solid #000; Background-color: #FFF; font-weight:700;}
. calender{width:100%; margin-top:3%; overflow:hidden; display:none;}
. selectmouth{Background-color: #F30; width:94%; overflow:hidden;padding:2% 3%;border-radius:5px 5px 0 0;}
. Selectmouth p{float:left; width:33%; color: #FFF; font-weight:700; cursor:pointer;}
. Selectmouth. selectdate{width:100%; Background-color: #F30; border:none; color: #FFF; font-weight:700; Text-align: Center;}
. data_table{width:100%;border:1px solid #cccccc; border-collapse:collapse;}
. data_table thead{Background-color: #333;}
. data_table thead td{color: #FFF; text-align:center;border:1px solid #333; border-collapse:collapse; padding:1% 0;}
. data_table tbody td{border:1px solid #cccccc; border-collapse:collapse; Text-align:center;color: #0C6;p adding:1% 0;}
. data_table tbody td.orderdate{color: #000;}
. data_table tbody td.tdselect{color: #fff; Background-color: #999}
</style>
<body>
<div class= "Choosecal" >
<div class= "Ccaltop" >
<div class= "Caltline1" >
<p class= "Bookdate" > select Check-in date ......</p>
<p></p>
</div>
<div class= "Caltline2" >
<p style= "width:80%; Text-align:left; " >
<input type= "text" value= "" class= "Datetext datetoday" readonly=readonly/> To
<input type= "text" value= "" class= "Datetext dateendday" readonly=readonly/>
</p>
<p><input type= "button" value= "OK" class= "Btsure"/></p>
</div>
</div>
<div class= "Calender" >
<div class= "Selectmouth" >
<p style= "Text-align:right" class= "Lastmonth" ><</p>
<p><input type= "text" class= "selectdate" value= "February 2014" readonly=readonly/></p>
<p class= "Nextmonth" >></p>
</div>
<table class= "data_table" cellspacing= "0px" >
<thead>
<tr>
<td> Day </td><td> One </td><td> two </td><td> three </td><td> four </td> <td> Five </td><td> six </td>
</tr>
</thead>
<tbody>
<tr>
<td>1</td><td></td><td></td><td></td><td></td>< Td></td><td></td>
</tr>
<tr>
<td>1</td><td></td><td></td><td></td><td></td>< Td></td><td></td>
</tr>
<tr>
<td>1</td><td></td><td></td><td></td><td></td>< Td></td><td></td>
</tr>
<tr>
<td>1</td><td></td><td></td><td></td><td></td>< Td></td><td></td>
</tr>
<tr>
<td>1</td><td></td><td></td><td></td><td></td>< Td></td><td></td>
</tr>
<tr>
<td>1</td><td></td><td></td><td></td><td></td>< Td></td><td></td>
</tr>
</tbody>
</table>
</div>
</div>
<script>
Window.onload=function () {
var mydate=new Date ();
var thisyear=mydate.getfullyear ();
var thismonth=mydate.getmonth () +1;
var thisday=mydate.getdate ();
var mydate1=new Date ();
var thisyear1=mydate1.getfullyear ();
var thismonth1=mydate1.getmonth () +1;
var thisday1=mydate1.getdate ();
var selectday=thisday; Mark Date
var indate=thisday;//check-in date
var inmonth=thismonth; month of stay
var outdate=thisday+1; Check-out Date
var outmonth=thismonth; Check out month
var datetxt= "Datetoday";
var Datefirst;
var Datesecond;
function InitData () {//Date initial fill
var tdheight=jquery (". data_table tbody tr"). EQ (0). Find ("TD"). Height ();
JQuery (". data_table tbody TD"). CSS ("height", tdheight);
JQuery (". Selectdate"). Val (thisyear+ "Year" +thismonth+ "month");
var days=getdaysinonemonth (Thisyear,thismonth);
var weekday=getfirstday (Thisyear,thismonth);
Setcalender (Days,weekday);
Markdate (Thisyear,thismonth,selectday);
Orderabledate (Thisyear,thismonth,thisday);
}
InitData ();
JQuery (". Datetoday"). Val (thisyear+ "-" +thismonth+ "-" +thisday ");
JQuery (". Dateendday"). Val (thisyear+ "-" +thismonth+ "-" + (thisday+1));
function Orderabledate (thisyear,thismonth,thisday) {//date on which the reservation can be made
if (THISYEAR&LT;THISYEAR1) {
JQuery (". data_table tbody TD"). AddClass ("OrderDate");
JQuery (". data_table tbody TD"). Removeclass ("Usedate");
}else if (thisyear==thisyear1) {
if (thismonth<thismonth1) {
JQuery (". data_table tbody TD"). AddClass ("OrderDate");
JQuery (". data_table tbody TD"). Removeclass ("Usedate");
}else if (thismonth==thismonth1) {
for (Var j=0;j<6;j++) {
for (Var i=0;i<7;i++) {
var tdhtml=jquery (". data_table tbody tr"). EQ (j). Find ("TD"). EQ (i). html ();
if (tdhtml<thisday) {
JQuery (". data_table tbody tr"). EQ (j). Find ("TD"). EQ (i). addclass ("OrderDate");
JQuery (". data_table tbody tr"). EQ (j). Find ("TD"). EQ (i). Removeclass ("Usedate");
}else{
JQuery (". data_table tbody tr"). EQ (j). Find ("TD"). EQ (i). Removeclass ("OrderDate");
}
}
}
}else{
JQuery (". data_table tbody TD"). Removeclass ("OrderDate");
}
}else{
JQuery (". data_table tbody TD"). Removeclass ("OrderDate");
}
}
function Markdate (thisyear,thismonth,thisday) {//Tag date
var datetxt=thisyear+ "Year" +thismonth+ "month";
var thisdatetxt=thisyear1+ "Year" +thismonth1+ "month";
JQuery (". data_table TD"). Removeclass ("Tdselect");
if (datetxt==thisdatetxt) {
for (Var j=0;j<6;j++) {
for (Var i=0;i<7;i++) {
var tdhtml=jquery (". data_table tbody tr"). EQ (j). Find ("TD"). EQ (i). html ();
if (tdhtml==thisday) {
JQuery (". data_table tbody tr"). EQ (j). Find ("TD"). EQ (i). addclass ("Tdselect");
}
}
}
}
}
function Getdaysinonemonth (year,month) {//Count the total number of days of a month
Month=parseint (month,10);
var d=new Date (year,month,0);
return D.getdate ();
}
function Getfirstday (year,month) {//Calculate the first day of the month is the days of the week
Month=month-1;
var d=new Date (year,month,1);
return D.getday ();
}
function Setcalender (days,weekday) {//calendar filled in date
var a=1;
for (Var j=0;j<6;j++) {
for (Var i=0;i<7;i++) {
if (j==0&&i<weekday) {
JQuery (". data_table tbody tr"). EQ (0). Find ("TD"). EQ (i). HTML ("");
JQuery (". data_table tbody tr"). EQ (0). Find ("TD"). EQ (i). Removeclass ("Usedate");
}else{
if (a<=days) {
JQuery (". data_table tbody tr"). EQ (j). Find ("TD"). EQ (i). html (a);
JQuery (". data_table tbody tr"). EQ (j). Find ("TD"). EQ (i). addclass ("Usedate");
a++;
}else{
JQuery (". data_table tbody tr"). EQ (j). Find ("TD"). EQ (i). HTML ("");
JQuery (". data_table tbody tr"). EQ (j). Find ("TD"). EQ (i). Removeclass ("Usedate");
a=days+1;
}
}
}
}
}
function Errorreset () {//date after error, data reset
THISYEAR=THISYEAR1;
Thismonth=thismonth1;
Thisday=thisday1;
Selectday=thisday1;
Indate=thisday1;
Inmonth=thismonth1;
outdate=thisday1+1;
Outmonth=thismonth1;
InitData ();
}
JQuery (". data_table tbody Td.usedate"). Live ("Click", Function () {//click Date effect
var thishtml=parseint (JQuery (this). html ());
JQuery (". data_table TD"). Removeclass ("Tdselect");
JQuery (This). addclass ("Tdselect");
selectday=thishtml;
if (datetxt== "Datetoday") {
JQuery (". Datetoday"). Val (thisyear+ "-" +thismonth+ "-" +selectday ");
Indate=selectday;
Inmonth=thismonth;
}else{
JQuery (". Dateendday"). Val (thisyear+ "-" +thismonth+ "-" +selectday ");
Outdate=selectday;
Outmonth=thismonth;
if (outmonth<inmonth) {
Alert ("Date filled in error");
JQuery (". Datetoday"). Val (thisyear1+ "-" +thismonth1+ "-" +thisday1 ");
JQuery (". Dateendday"). Val (thisyear1+ "-" +thismonth1+ "-" + (thisday1+1));
Errorreset ();
}else if (outmonth==inmonth) {
if (outdate<=indate) {
Alert ("Date filled in error");
JQuery (". Datetoday"). Val (thisyear1+ "-" +thismonth1+ "-" +thisday1 ");
JQuery (". Dateendday"). Val (thisyear1+ "-" +thismonth1+ "-" + (thisday1+1));
Errorreset ();
}
}
}
});
JQuery (". Datetoday"). Click (function () {//select check-in date
datetxt= "Datetoday";
});
JQuery (". Dateendday"). Click (function () {//select Check out date
datetxt= "Dateendday";
});
JQuery (". Lastmonth"). Click (function () {//one months
thismonth--;
if (thismonth==0) {
thismonth=12;
thisyear--;
}
InitData ();
});
JQuery (". Nextmonth"). Click (function () {//one months
thismonth++;
if (thismonth==13) {
thismonth=1;
thisyear++;
}
InitData ();
});
JQuery (". Btsure"). Click (function () {//date determined
var start = new Date ($ (". Datetoday"). Val ());
var end = new Date ($ (". Dateendday"). Val ());
var diff = parseint ((end-start)/(1000*3600*24));
JQuery (". Bookdate"). HTML (inmonth+ "month" +indate+ "Day to" +outmonth+ "month" +outdate+ "Day (" +diff+ ") Night")
});
JQuery (". Caltline1"). Toggle (
function () {
JQuery (". Caltline2"). Slidedown (500);
JQuery (". Calender"). FadeIn (500);
Errorreset ();
JQuery (". Caltline1"). FIND ("img"). attr ("src", "images/iconpointup.png");
},
function () {
JQuery (". Caltline2"). Slideup (500);
JQuery (". Calender"). FadeOut (500);
JQuery (". Caltline1"). FIND ("img"). attr ("src", "images/iconpoint.png");
}
);
}
</script>
</body>

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.