且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

好程序员web前端分享用JavaScript实现的5个常见函数

更新时间:2021-08-27 13:04:52

<div id="container"></div>
<script>
  var count = 1
  var container = document.getElementById('container')
  function getUserAction(e) {
    // 空格
    if (e.keyCode === 32) {
      container.innerHTML = count++
    }
  }
  // document.onkeydown = debounce(getUserAction, 1000, false, true)
  document.onkeydown = throttle(getUserAction, 1000, true, true)
  function debounce(func, wait, leading, trailing) {}
  function throttle(func, wait, leading, trailing) {}
</script>