How can I hide/show a div when a button is clicked?

前端 未结 8 1960
陌清茗
陌清茗 2020-12-04 22:02

I have a div that contains a register wizard, and I need hide/show this div when a button is clicked. How can I do this?

Below I show you t

8条回答
  •  忘掉有多难
    2020-12-04 22:27

    The following solution is:

    • briefest. Somewhat similar to here. It's also minimal: The table in the DIV is orthogonal to your question.
    • fastest: getElementById is called once at the outset. This may or may not suit your purposes.
    • It uses pure JavaScript (i.e. without JQuery).
    • It uses a button. Your taste may vary.
    • extensible: it's ready to add more DIVs, sharing the code.

    mydiv = document.getElementById("showmehideme");
    
    function showhide(d) {
        d.style.display = (d.style.display !== "none") ? "none" : "block";
    }
    #mydiv { background-color: #ffffd; }
    
    
    This div will show and hide on button click.

提交回复
热议问题