<!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> <div class="box"> <button data-action="remove">移除</button> <button data-action="new">新建</button> <button data-action="revise">修改</button> <button data-action="search">查找</button> </div> <script> var boxEle=document.querySelector('.box') boxEle.addEventListener('click',function(e){ var btnEle=e.target; console.log(btnEle.dataset.action); }) </script> </body> </html>
标签:btnEle,区分,JavaScript,按钮,var,boxEle From: https://www.cnblogs.com/theYT/p/16873324.html