创建一个秒表,它似乎没有在IE中运行?

时间:2017-06-01 12:36:44

标签: javascript html css

我创建了这是一个秒表,但好像它不想在IE中运行,它在chrome中工作正常但它需要放入一个只在IE中运行的网站请帮助...



var h1 = document.getElementsByTagName('h1')[0],
  start = document.getElementById('start'),
  stop = document.getElementById('stop'),
  clear = document.getElementById('clear'),
  seconds = 0,
  minutes = 0,
  hours = 0,
  t;

function add() {
  seconds++;
  if (seconds >= 60) {
    seconds = 0;
    minutes++;
    if (minutes >= 60) {
      minutes = 0;
      hours++;
    }
  }

  h1.textContent = (hours ? (hours > 9 ? hours : "0" + hours) : "00") + ":" + (minutes ? (minutes > 9 ? minutes : "0" + minutes) : "00") + ":" + (seconds > 9 ? seconds : "0" + seconds);

  timer();
}

function timer() {
  t = setTimeout(add, 1000);
}
// timer();


/* Start button */
start.onclick = function() {
  timer();
  start.style.visibility = "hidden";
  stop.style.visibility = "visible";
}


/* Stop button */
stop.onclick = function() {
  clearTimeout(t);
  stop.style.visibility = "hidden";
  start.style.visibility = "visible";
}

/* Clear button */
clear.onclick = function() {
  clearTimeout(t);
  h1.textContent = "00:00:00";
  seconds = 0;
  minutes = 0;
  hours = 0;
  stop.style.visibility = "hidden";
  start.style.visibility = "visible";
}

#timer {
  position: absolute;
  top: 35px;
  left: 20px;
}

.time {
  font-size: 42px;
  margin-left: 40px;
  margin-top: 5px;
}

.btn-timer {
  width: 80px;
  height: 40px;
  cursor: pointer;
  font-family: helvetica, sans-serif;
  font-size: 16px;
}

h1 {
  font: bold 24px Helvetica, sans-serif;
  color: black;
}

h1 {
  display: block;
  font-size: 2em;
  -webkit-margin-before: 0.67em;
  -webkit-margin-after: 0.67em;
  -webkit-margin-start: 0px;
  -webkit-margin-end: 0px;
  font-weight: bold;
}

<div id="timer">
  <button id="start" class="btn-timer">START</button>
  <button id="stop" class="btn-timer" style="visibility:hidden">STOP</button>
  <button id="clear" class="btn-timer">CLEAR</button>
  <h1 class="time"><time>00:00:00</time></h1>
</div>
&#13;
&#13;
&#13;

任何帮助都会很棒

0 个答案:

没有答案