如何使用JavaScript更改类的显示?

Lèl*_*ull 5 html javascript css

所以我有这段代码:

    function show_all()
    {
    	document.getElementByClassName('login').style.display = 'inline';
    	document.getElementById('button-hide').style.display = 'inline';
    	document.getElementById('button-show').style.display = 'none';
    };
    function hide_all()
    {
    	document.getElementByClassName('login').style.display = 'none';
    	document.getElementById('button-hide').style.display = 'none';
    	document.getElementById('button-show').style.display = 'inline';
    };
Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<nav>
    	<input type="button" value="Show login Buttons" id="button-show" onclick="show_all();"/>
    	<input type="button" value="Hide login Buttons" id="button-hide" onclick="hide_all();"/>
    </nav>
        <p class="login">Username:</p>
        <img src="un.png" class="login"/>
        <p class="login">Password:</p>
    <p>Something not ment to be hidden.</p>
        <img src="pass.png" class="login"/>
Run Code Online (Sandbox Code Playgroud)

而且我需要显示/隐藏整个班级;我有大约50个带有“登录”类元素的块,我只想使用JavaScript来显示它。

Ven*_*ryx 5

展示:

document.querySelectorAll(".login").forEach(a=>a.style.display = "initial");
Run Code Online (Sandbox Code Playgroud)

隐藏:

document.querySelectorAll(".login").forEach(a=>a.style.display = "none");
Run Code Online (Sandbox Code Playgroud)


Lèl*_*ull 0

我只是使用了 jQuery 的离线版本。