📜  空格键 - 任何代码示例

📅  最后修改于: 2022-03-11 14:57:45.231000             🧑  作者: Mango

代码示例1
var hits = 0;
let url = new URL('https://spacebarcounter.org');
var hitElement = document.querySelector( '.hits' );
document.body.onkeyup = function(e) {
  if( e.keyCode == 32 ) {
    addHit();
  }
}

var addHit = function() {
  hits++;
  renderHits();
}

var renderHits = function() {
  hitElement.innerHTML = hits;
}

var resetHits = function() {
  hits = 0;
  renderHits();
}