表中的javascript在响应时不起作用

时间:2017-12-17 04:46:05

标签: javascript jquery datatables footable stacktable.js

    jQuery.noConflict();
(function($) {
  $(function() {
    function toTimeString(seconds) {
      return (new Date(seconds * 1000)).toUTCString().match(/(\d\d:\d\d:\d\d)/)[0];
    }

    function startTimer() {
      var dataStartElem = jQuery(this);
      var dataStart = dataStartElem.attr('data-start');
      if (dataStart == 'false') {
        dataStartElem.attr('data-start', 'true');
        var nextElem = dataStartElem.parent('td').next('.count');
        var duration = dataStartElem.attr('data-value');
        var a = duration.split(':');
        var seconds = (+a[0]) * 60 * 60 + (+a[1]) * 60 + (+a[2]);
        setInterval(function() {
          seconds--;
          if (seconds >= 0) {
            nextElem.html(toTimeString(seconds));
            dataStartElem.attr('data-start', 'false');
          }
          if (seconds === 0) {
            alert('time out');
            clearInterval(seconds);
          }
        }, 1000);
      }
    }
    jQuery('.timer').on('click', startTimer);
    $('table').stacktable();
  });
})(jQuery);

小提琴演示https://jsfiddle.net/arra6j6h/6/

表中的javascript计时器不起作用,响应时不显示时间,但响应时一切正常

0 个答案:

没有答案