Javascript document.GetElementsByCassName在我的脚本中不可用

Javascript document.GetElementsByCassName在我的脚本中不可用,javascript,Javascript,我正在做一个使用这个脚本的项目。此脚本使用当前时间并从给定时间中减去它。。我给出了9 102017,它给出了29d 23h 3m 2s作为剩余时间的输出 <!DOCTYPE html> <html> <head> <title>Script</title> </head> <body> <script type='text/javascript'> // Set the date we're

我正在做一个使用这个脚本的项目。此脚本使用当前时间并从给定时间中减去它。。我给出了9 102017,它给出了29d 23h 3m 2s作为剩余时间的输出

 <!DOCTYPE html>
<html>
<head>
    <title>Script</title>
</head>
<body>
<script type='text/javascript'>
// Set the date we're counting down to
var countDownDate = new Date('9 10,2017 00:00:00').getTime(); //m d, y h m s

// Update the count down every 1 second
var x = setInterval(function() {

    // Get todays date and time
    var now = new Date().getTime();

    // Find the distance between now an the count down date
    var distance = countDownDate - now;

    // Time calculations for days, hours, minutes and seconds
    var days = Math.floor(distance / (1000 * 60 * 60 * 24));
    var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
    var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
    var seconds = Math.floor((distance % (1000 * 60)) / 1000);

    // Output the result in an element with id='time'
                  document.getElementById('rtime').innerHTML = days + 'd ' + hours + 'h '
    + minutes + 'm' + seconds + 's';
    // If the count down is over, write some text 
    if (distance <= 0) {
      clearInterval(x);
                   document.getElementById('rtime').innerHTML = 'EXPIRED'; // SUBMIT FORM;
  }
}, 1000); </script>
<h4 id='rtime'></h4>
<h4 id='rtime'></h4>
<h4 id='rtime'></h4>
</body>
</html>

剧本
//确定我们倒计时的日期
var countDownDate=新日期('9 102017 00:00:00')。getTime()//m d,y h m s
//每1秒更新一次倒计时
var x=setInterval(函数(){
//获取今天的日期和时间
var now=new Date().getTime();
//找出现在和倒计时日期之间的距离
var距离=倒计时日期-现在;
//天、小时、分钟和秒的时间计算
变量天数=数学楼层(距离/(1000*60*60*24));
可变小时数=数学楼层((距离%(1000*60*60*24))/(1000*60*60));
var分钟=数学楼层((距离%(1000*60*60))/(1000*60));
var秒=数学楼层((距离%(1000*60))/1000);
//在id='time'的元素中输出结果
document.getElementById('rtime').innerHTML=days+'d'+hours+'h'
+分钟+米+秒+秒;
//如果倒计时结束,写一些文字
如果(距离
//设置我们倒计时的日期
var countDownDate=新日期('9 102017 00:00:00')。getTime();//m d,y h m s
//每1秒更新一次倒计时
var x=setInterval(函数(){
//获取今天的日期和时间
var now=new Date().getTime();
//找出现在和倒计时日期之间的距离
var距离=倒计时日期-现在;
//天、小时、分钟和秒的时间计算
变量天数=数学楼层(距离/(1000*60*60*24));
可变小时数=数学楼层((距离%(1000*60*60*24))/(1000*60*60));
var分钟=数学楼层((距离%(1000*60*60))/(1000*60));
var秒=数学楼层((距离%(1000*60))/1000);
//在id='time'的元素中输出结果
对于(变量y=0;y<3;y++){
document.getElementsByClassName('rtime')[y].innerHTML=days+'d'+hours+'h'+
分钟+米+秒+秒;
};
//如果倒计时结束,写一些文字

if(distance
getElementsByClassName
返回节点列表。还有什么是
.innerHTML[y]
[y]
需要在函数调用之后,而不是
之后。innerHTML
querySelector和getElementsByClassName返回节点列表,您需要对它们进行迭代。检查MDN,了解这一点,或者了解jQuery。lol
gEBCN
肯定不会返回数组,请阅读。
<!DOCTYPE html>
<html>
<head>
    <title>Script</title>
</head>
<body>
<script type='text/javascript'>
// Set the date we're counting down to
var countDownDate = new Date('9 10,2017 00:00:00').getTime(); //m d, y h m s

// Update the count down every 1 second
var x = setInterval(function() {

    // Get todays date and time
    var now = new Date().getTime();

    // Find the distance between now an the count down date
    var distance = countDownDate - now;

    // Time calculations for days, hours, minutes and seconds
    var days = Math.floor(distance / (1000 * 60 * 60 * 24));
    var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
    var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
    var seconds = Math.floor((distance % (1000 * 60)) / 1000);

    // Output the result in an element with id='time'
    for(var y=0;y<=3;y++){
                  document.getElementsByClassName('rtime').innerHTML[y] = days + 'd ' + hours + 'h '
    + minutes + 'm' + seconds + 's';
};
    // If the count down is over, write some text 
    if (distance <= 0) {
      clearInterval(x);
                   document.getElementsByClassName('rtime').innerHTML[0] = 'EXPIRED'; // SUBMIT FORM;
  }
}, 1000); </script>
<h4 class='rtime'></h4>
<h4 class='rtime'></h4>
<h4 class='rtime'></h4>
</body>
</html>