其中.btns代表在总体的div中定义的class类data-id为在button中定义的标记字符
<div class="btns"> <div class="btn-switch active-map" data-id="0">1</div> <div class="btn-switch" data-id="1">2</div> <div class="btn-switch" data-id="2">3</div> </div> document.querySelector(".btns").addEventListener("click", function(event) { var id = event.target.getAttribute("data-id"); }