quick_list.html 907 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>快捷报表</title>
  6. </head>
  7. <body>
  8. <div>建设中....</div>
  9. <button onclick="debounceTask">testDebounce</button>
  10. </body>
  11. <script>
  12. //防抖
  13. function debounce (fn , delay) {
  14. let timer;
  15. return function (...args) {
  16. if (timer) {
  17. clearTimeout(timer)
  18. }
  19. timer = setTimeout(()=>{
  20. fn.apply(this,args)
  21. },delay)
  22. }
  23. }
  24. //test
  25. function task() {
  26. console.log('run')
  27. }
  28. const debounceTask = debounce(task,1000);
  29. //节流
  30. function throttle(fn , delay) {
  31. let last = 0; //last time
  32. return function (...args) {
  33. const now = Date.now();
  34. if(now - last > delay){
  35. last = now;
  36. fn.apply(this,args)
  37. }
  38. }
  39. }
  40. function task2() {
  41. console.log('run2')
  42. }
  43. const throttleTask = throttle(task2,1000)
  44. </script>
  45. </html>