简体   繁体   English

隐藏/显示多个div

[英]hide / show multiple div

I would like to hide / show some div box, by clicking one text line.我想通过单击一个文本行来隐藏/显示一些div框。 To summarize, it must do something like Android File Explorer.总而言之,它必须执行类似 Android 文件资源管理器的操作。

在此处输入图片说明

在此处输入图片说明

These 2 pictures show the difference when I click on the Mes Vidéos text field.当我单击Mes Vidéos文本字段时,这 2 张图片显示了不同之处。

Here is a part of my current code :这是我当前代码的一部分:

 function folderChange(param) { var video=document.getElementById('v'); var file=document.getElementById('f'); if(param==1) { video.style.display = "block"; file.style.display = "none"; } else { file.style.display = "block"; video.style.display = "none"; } }
 .filefolder { display: none; } .videofolder { display: block; }
 <div class="groove2"></div> <div class="chemin filefolder" id="f" style="background-color:#FAF9F8" style="color:#BDBCBA"><font color="#575654">Flashdisk <b>> Mes Fichiers</b></font></div> <div class="chemin videofolder" id="v" style="background-color:#FAF9F8" style="color:#BDBCBA"><font color="#575654">Flashdisk ><b onclick="folderChange(0)"> Mes Fichiers</b> ><b> Mes Vidéos</b></font></div> <div class="groove2"></div> <div id="madiv"> <div class="videofolder" id="v"> <div> <input type="checkbox" id="contactChoice1" name="fichier" value="Video1"> <img class="icone" src="video.jpg"> <label for="Video1">Video1.mp4</label> </div> <div class="groove"></div> </div> <div id="f" class="filefolder"> <div class="folder"> <img class="icone" src="dossier.jpg" onclick="folderChange(1)"> <p onclick="folderChange(1)"><b>Mes Vidéos</b></p> </div> <div class="groove"></div> </div> <div class="filefolder"> <div id="f" class="blok"> <input class="off" type="checkbox" disabled="true" id="contactChoice1" name="fichieroff" value="Video1"> <img class="icone" src="xls.jpg"> <label for="Video1"><b>Resultats.xlsx</b></label> </div> <div class="groove"></div> </div>

What I'm expected to do is to change the display value of videofolder and filefolder when I click on Mes Vidéos , but on the screen, nothing change (or just the path display).我期望做的是在单击Mes Vidéos时更改videofolderfilefolderdisplay值,但在屏幕上,没有任何变化(或只是路径显示)。

I'm pretty newbie on HTML and Javascript.我是 HTML 和 Javascript 的新手。

NB : there is no file reader currently, I'm just working on the display.注意:目前没有文件阅读器,我只是在显示器上工作。

If you only have two types of things to show/hide, you can iterate through them with a single line, and apply classList.toggle() to them:如果你只有两种类型的东西要显示/隐藏,你可以用一行遍历它们,并将classList.toggle()应用于它们:

 function folderChange() { document.querySelectorAll(".video, .file").forEach(el => el.classList.toggle("show")) }
 .video, .file { display: none } .show { display: block }
 <button onclick="folderChange()">Show Files</button> <button onclick="folderChange()">Show Videos</button> <p class="video">video a</p> <p class="file show">file a</p> <p class="video">video b</p> <p class="video">video c</p> <p class="file show">file b</p> <p class="file show">file c</p> <p class="file show">file d</p> <p class="video">video d</p> <p class="video">video e</p> <p class="file show">file e</p>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM