银行假日英国javascript jus

时间:2014-06-01 15:17:06

标签: javascript date if-statement

我创建了一个简单的页面来显示下一个英国银行假期的是/否以及下一个日期,但它不起作用。我已经尝试使用与.gov json api集成的代码,但只是可以;因为这样快速的工作所以工作得很好。有什么想法,我做错了吗?

<html>
<head>
<script type="text/javascript">
var date=new Date();
var year=date.getFullYear();
var month=date.getMonth();
var day=date.getDate(); // fixed
function SetDivContent() {
    var div=document.getElementById('date_dependent');

    //2014
     if (year==2014 && month==4) { // The JavaScript months order is 0-11, not 1-12, so Jan = 0
        if (day>=1) { // if the day is greater than thw 3rd but less than the 26th
            div.innerHTML='<div class="holiday" ><h1>No.</h1> The Next Bank Holiday is 26th May';
        }
        else if (month==4 && day==26) { // 26 May Monday Spring bank holiday 2014
            div.innerHTML='<div class="holiday" ><h1 >Yes</h1> The Next Bank Holiday is 25th August</div>';
        }
        else if (month==4 && day>26) { // days after that until...
            div.innerHTML='<div class="holiday" ><h1>No.</h1> The Next Bank Holiday is 25th August</div>';
        }
        else if (month==5 && day>1) { // days after that until...
            div.innerHTML='<div class="holiday" ><h1>No.</h1> The Next Bank Holiday is 25th August</div>';
        }
    else if (month==7 && day==25) { // 25 August Monday Summer bank holiday 2014
            div.innerHTML='<div class="holiday" ><h1 >Yes</h1> The Next Bank Holiday is 25th August</div>';
        }
    else if (month==7 && day>=25) { // // days after that until...
            div.innerHTML='<div class="holiday" ><h1 >No</h1> The Next Bank Holiday is 25 December</div>';
        }
    else if (month==11 && day==25) { // // xmas day 2014
            div.innerHTML='<div class="holiday" ><h1 >Yes</h1> The Next Bank Holiday is 26 December</div>';
        }
    else if (month==11 && day==26) { // // boxing day 2014
            div.innerHTML='<div class="holiday" ><h1 >Yes</h1> The Next Bank Holiday is 1st January 2015</div>';
        }
    else if (month==11 && day>=26) { // // days after that until...
            div.innerHTML='<div class="holiday" ><h1 >No</h1> The Next Bank Holiday is 1st January 2015</div>';
        }

        //2015
    else if (year==2015 && month==0 && day==1) { // // New Year's Day
            div.innerHTML='<div class="holiday" ><h1 >Yes</h1> The Next Bank Holiday is 3rd April </div>';
        }
    else if (year==2015 && month==0 && day>=1) { // // days after that until...
            div.innerHTML='<div class="holiday" ><h1 >No</h1> The Next Bank Holiday is 3rd April </div>';
        }
    else if (year==2015 && month==3 && day==3) { // // 3 April Friday Good Friday
            div.innerHTML='<div class="holiday" ><h1 >Yes</h1> The Next Bank Holiday is 6 April </div>';
        }
    else if (year==2015 && month==3 && day>=3) { // // days after that until...
            div.innerHTML='<div class="holiday" ><h1 >No</h1> The Next Bank Holiday is 6th April </div>';
        }
    else if (year==2015 && month==3 && day==6) { // // Easter
            div.innerHTML='<div class="holiday" ><h1 >Yes</h1> The Next Bank Holiday is 4th May </div>';
        }
    else if (year==2015 && month==3 && day>=6) { // // days after that until...
            div.innerHTML='<div class="holiday" ><h1 >No</h1> The Next Bank Holiday is 4th May </div>';
        }
    else if (year==2015 && month==4 && day==4) { // // 4th May
            div.innerHTML='<div class="holiday" ><h1 >Yes</h1> The Next Bank Holiday is 25th May </div>';
        }
    else if (year==2015 && month==4 && day>=4) { // // days after that until...
            div.innerHTML='<div class="holiday" ><h1 >No</h1> The Next Bank Holiday is 25th May </div>';
        }
    else if (year==2015 && month==4 && day==25) { // // 25th May
            div.innerHTML='<div class="holiday" ><h1 >Yes</h1> The Next Bank Holiday is 31st August </div>';
        }
    else if (year==2015 && month==4 && day>=25) { // // days after that until...
            div.innerHTML='<div class="holiday" ><h1 >No</h1> The Next Bank Holiday is 31st August </div>';
        }
    else if (year==2015 && month==7 && day==31) { // // 31st August
            div.innerHTML='<div class="holiday" ><h1 >Yes</h1> The Next Bank Holiday is 25th December </div>';
        }
    else if (year==2015 && month==7 && day>=31) { // // days after that until...
            div.innerHTML='<div class="holiday" ><h1 >No</h1> The Next Bank Holiday is 25th December </div>';
        }
    else if (year==2015 && month==11 && day==25) { // //  25th December
            div.innerHTML='<div class="holiday" ><h1 >Yes</h1> The Next Bank Holiday is 26th December </div>';
        }
    else if (year==2015 && month==11 && day==26) { // //  26th December
            div.innerHTML='<div class="holiday" ><h1 >Yes</h1> The Next Bank Holiday is 1st Jan 2016 </div>';
        }


    //2016
    else if (year==2016 && month==0 && day==1) { // // New Year's Day
            div.innerHTML='<div class="holiday" ><h1 >Yes</h1> The Next Bank Holiday is 25th March </div>';
        }
    else if (year==2016 && month==0 && day>=1) { // // days after that until...
            div.innerHTML='<div class="holiday" ><h1 >No</h1> The Next Bank Holiday is 25th March </div>';
        }
    else if (year==2016 && month==2 && day==25) { // // 25th march  Good Friday
            div.innerHTML='<div class="holiday" ><h1 >Yes</h1> The Next Bank Holiday is 28th March </div>';
        }
    else if (year==2016 && month==2 && day>=25) { // // days after that until...
            div.innerHTML='<div class="holiday" ><h1 >No</h1> The Next Bank Holiday is 28th March </div>';
        }
    else if (year==2016 && month==3 && day==28) { // // 28th Easter monday
            div.innerHTML='<div class="holiday" ><h1 >Yes</h1> The Next Bank Holiday is 2nd May </div>';
        }
    else if (year==2016 && month==3 && day>=28) { // // days after that until...
            div.innerHTML='<div class="holiday" ><h1 >No</h1> The Next Bank Holiday is 2nd May </div>';
        }
    else if (year==2016 && month==4 && day==2) { // // 2nd may bank hol
            div.innerHTML='<div class="holiday" ><h1 >Yes</h1> The Next Bank Holiday is 30th May </div>';
        }
    else if (year==2016 && month==4 && day>=2) { // // days after that until...
            div.innerHTML='<div class="holiday" ><h1 >No</h1> The Next Bank Holiday is 30th May </div>';
        }
    else if (year==2016 && month==4 && day==30) { // // 30th May
            div.innerHTML='<div class="holiday" ><h1 >Yes</h1> The Next Bank Holiday is 29th August </div>';
        }
    else if (year==2016 && month==4 && day>=30) { // // days after that until...
            div.innerHTML='<div class="holiday" ><h1 >No</h1> The Next Bank Holiday is 29th August </div>';
        }
    else if (year==2016 && month==7 && day==29) { // // 29th August
            div.innerHTML='<div class="holiday" ><h1 >Yes</h1> The Next Bank Holiday is 25th December </div>';
        }
    else if (year==2016 && month==7 && day>=29) { // // days after that until...
            div.innerHTML='<div class="holiday" ><h1 >No</h1> The Next Bank Holiday is 25th December </div>';
        }
    else if (year==2016 && month==11 && day==25) { // //  25th December
            div.innerHTML='<div class="holiday" ><h1 >Yes</h1> The Next Bank Holiday is 26th December </div>';
        }
    else if (year==2016 && month==11 && day==26) { // //  26th December
            div.innerHTML='<div class="holiday" ><h1 >Yes</h1> The Next Bank Holiday is 1st Jan 2016 </div>';
        }

}

    else if (year==2017 && month>=0) div.innerHTML='No'; // OPTIONAL - just to ensure that content 3 is displayed even after December.
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
body,td,th {
 font-family: Arial, Helvetica, sans-serif;
}
</style>
<link href="styles.css" rel="stylesheet" type="text/css">
</head>

<body onLoad="SetDivContent()">
<div class="holiday"><h2>Is it a bank holiday today?</h2></div>

<!--Display holiday Yes/No--->
<div id="date_dependent" align="center"></div>
<p>&nbsp;</p>
</body>
</html>

0 个答案:

没有答案