简体   繁体   中英

Dropdown menu remain open after click and refresh

I have a problem on how to make my dropdown remain open after clicking and avoid closing after refresh.

Here's what I've done.

<button class="dropdown_btn">
   <span>Sample</span>
</button>
<div class="dropdown-container">
   <a href="sample.php">Sample 1</a>
   <a href="sample.php">Sample 2</a>
</div>
<br>
<button class="dropdown_btn">
  <span>Sample</span>
</button>
<div class="dropdown-container">
   <a href="sample.php">Sample 1</a>
   <a href="sample.php">Sample 2</a>
</div>

Jsfiddle Link: https://jsfiddle.net/Mandy201/7w8t2muc/

You can use the localStorage with a simply flag. On open the flag become true, on close the flag become false. For the refresh you need to test your var contains in localStorage . If is true, display the menu, if is false do not display the menu

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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