1.去官网下载lodash.js:Lodash 简介 | Lodash 中文文档 | Lodash 中文网
2.创建html引入js
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <button id="btn">点击防抖</button> </body> <script src="./lodash.min.js"></script> <script> var btns = document.getElementsByTagName("button"); //一定要这么写,要不不生效 document.getElementById('btn').onclick = _.debounce(function () { console.log("防抖了"); }, 2000);