Mutiple buttons with the same name showing different divs

后端 未结 4 1776
名媛妹妹
名媛妹妹 2021-01-28 07:42

I have a large amount of buttons all used to display a div before it, my question is instead of having 20 different javascript functions which all do the same thing, is it possi

4条回答
  •  半阙折子戏
    2021-01-28 08:27

    HTML:

    JavaScript:

    var buttons = document.getElementsByClassName("drop-button");
    for(var i = 0; i < buttons.length; i++) {
        buttons[i].addEventListener("click", function(){ this.style.display="block"; });
    {
    

提交回复
热议问题