Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 页面上的所有7个倒计时(7个分区)_Javascript_Jquery_Countdown - Fatal编程技术网

Javascript 页面上的所有7个倒计时(7个分区)

Javascript 页面上的所有7个倒计时(7个分区),javascript,jquery,countdown,Javascript,Jquery,Countdown,我怎样才能保证页面上总是有7个div(倒计时)?我为这个倒计时程序做了编程,现在只有两个,但我会再加上大约30个。我怎样才能保证页面上总是有7个倒计时 示例:一个倒计时完成并自动从页面中删除,另一个倒计时自动添加到底部 <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script> </head> <body> &l

我怎样才能保证页面上总是有7个div(倒计时)?我为这个倒计时程序做了编程,现在只有两个,但我会再加上大约30个。我怎样才能保证页面上总是有7个倒计时

示例:一个倒计时完成并自动从页面中删除,另一个倒计时自动添加到底部

<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
</head>
<body>
<script>
var d = new Date();
var n = d.getDay();
if(n == 1 || 2 || 3 || 4 || 5){
var timer1;
function cdtd1() {
    var sad1 = new Date();
    var dolazak1 = new Date(sad1.getFullYear(),sad1.getMonth(),sad1.getDate(),14,52,00);
    var timeDiff1 = dolazak1.getTime() - sad1.getTime();
    if (timeDiff1 <= 0) {
        clearInterval(timer1);
        $('#dani1Box').remove();
        $('#sati1Box').remove();
        $('#minute1Box').remove();
        $('#sekunde1Box').remove();


    }
    var sekunde1 = Math.floor(timeDiff1 / 1000);
    var minute1 = Math.floor(sekunde1 / 60);
    var sati1 = Math.floor(minute1 / 60);
    var dani1 = Math.floor(sati1 / 24);
    sati1 %= 24;
    minute1 %= 60;
    sekunde1 %= 60;

    $("#dani1Box").html(dani1);
    $("#sati1Box").html('7-Dubrava ' + sati1 + ':');
    $("#minute1Box").html(minute1 + ':');
    $("#sekunde1Box").html(sekunde1);

    timer1 = setTimeout(cdtd1, 1000);
}

$(document).ready(function() {
     cdtd1();
});

var timer2;
function cdtd2() {
    var sad2 = new Date();
    var dolazak2 = new Date(sad2.getFullYear(),sad2.getMonth(),sad2.getDate(),23,45,00);
    var timeDiff2 = dolazak2.getTime() - sad2.getTime();
    if (timeDiff2 <= 0) {
        clearInterval(timer2);
        $('#dani2Box').remove();
        $('#sati2Box').remove();
        $('#minute2Box').remove();
        $('#sekunde2Box').remove();

    }
    var sekunde2 = Math.floor(timeDiff2 / 1000);
    var minute2 = Math.floor(sekunde2 / 60);
    var sati2 = Math.floor(minute2 / 60);
    var dani2 = Math.floor(sati2 / 24);
    sati2 %= 24;
    minute2 %= 60;
    sekunde2 %= 60;
    $("#dani2Box").html(dani2);
    $("#sati2Box").html('6-Sopot ' + sati2 + ':');
    $("#minute2Box").html(minute2 + ':');
    $("#sekunde2Box").html(sekunde2);

    timer2 = setTimeout(cdtd2, 1000);
}

$(document).ready(function() {
     cdtd2();
});
}
</script>





<style type="text/css">
#dani1Box, #sati1Box, #minute1Box, #sekunde1Box, #dani2Box, #sati2Box, #minute2Box, #sekunde2Box{
         font-size:70px;
         color:#1f62a7;
         font-family:Sans-serif;
         display: inline-block;
}







</style>
  <center>
    <div>
    <div id="sati1Box"></div>
    <div id="minute1Box"></div>
    <div id="sekunde1Box"></div>
    </div>

<h1 style="font-family:Helvetica;color:#FFFFFF;font-size:15px;">&nbsp;</h1>

    <div>
    <div id="sati2Box"></div>
    <div id="minute2Box"></div>
    <div id="sekunde2Box"></div>
    </div>

   </center> 
</body>

var d=新日期();
var n=d.getDay();
如果(n==1 | | 2 | | 3 | | 4 | 5){
var定时器1;
函数cdtd1(){
var sad1=新日期();
var dolazak1=新日期(sad1.getFullYear(),sad1.getMonth(),sad1.getDate(),14,52,00);
var timeDiff1=dolazak1.getTime()-sad1.getTime();

if(timeDiff1)这个:
if(n==1 | | | 2 | | 3 | | 4 | | | | 5){/code>的计算结果总是为true,因为
2在JavaScript中被认为是“真实的”。你不能将
n
与那样的多个值进行比较。你需要做
if(n==1 | n==2 | n==3 | n==4 |n==124;{
。与Anthony的方法不同,你可以做
[1,2,3,4,5]。indexOf(n)!=-1
或者如果你可以假设一个整数,
n>0&&n<6