iOS上的JavaScript时钟/计时器脚本不起作用

时间:2018-08-03 11:59:06

标签: javascript timer http-post clock

我有Timer javascript功能,该功能运行良好,但是在iOS上,我只能看到aN:aN:aN的结果。这是代码:

 function getTimeRemaining(endtime) {
    var t = Date.parse(endtime) - Date.parse(new Date());
    var seconds = Math.floor((t / 1000) % 60);
    var minutes = Math.floor((t / 1000 / 60) % 60);
    var hours = Math.floor((t / (1000 * 60 * 60)) % 24);
    var days = Math.floor(t / (1000 * 60 * 60 * 24));
    return {
      'total': t,
      'days': days,
      'hours': hours,
      'minutes': minutes,
      'seconds': seconds
    };
  }

  function initializeClock(id, endtime) {
    var clock = document.getElementById(id);
    var daysSpan = clock.querySelector('.days');
    var hoursSpan = clock.querySelector('.hours');
    var minutesSpan = clock.querySelector('.minutes');
    var secondsSpan = clock.querySelector('.seconds');

    function updateClock() {
      var t = getTimeRemaining(endtime);

      hoursSpan.innerHTML = ('0' + t.hours).slice(-2);
      minutesSpan.innerHTML = ('0' + t.minutes).slice(-2);
      secondsSpan.innerHTML = ('0' + t.seconds).slice(-2);


      if (t.total <= 0) {
        $( "#end-of-translation" ).submit(); 
      }

        if($("#addtime_form").length == 0) {
          if(t.total <= 300000) {
            $("#addtime-form").append("<input id='addtime_form' type='submit' name='addtime' value='Add 15 minutes'>");
          }
        }
    }

    updateClock();
    var timeinterval = setInterval(updateClock, 1000);
  }

  var now = Date.parse(new Date());
  var seconds = Math.floor((now / 1000) % 60);
  var minutes = Math.floor((now / 1000 / 60) % 60);
  var left_to_hour = 60 * 60 * 1000 - (minutes * 60 + seconds) * 1000;

  initializeClock("clockdiv", deadline);

有人可以告诉我为什么我得到NaN而不是时间吗?

我的第二个问题是iOS上的POST请求。我在POST数组中找不到输入type = submit参数...,因此如果语句形式为:

,我需要在整个项目中进行更改
 if( $_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['submit'])) 

仅:

 if( $_SERVER['REQUEST_METHOD'] == 'POST')

有人有类似的问题吗?

0 个答案:

没有答案