简体   繁体   中英

Keep dropdown menu open even after visiting another page?

I have a drop down menu and I am trying to keep it open even after leaving the website and coming back.

Here is the php code that is in the file:

<?php
                $totalTrajectories = count($trajectory_data);
                $perColumnElement = round($totalTrajectories / 3);
                $counter = 1;
                foreach($trajectory_data as $key => $values){
                    echo getLtCards($values);
                    /*if($counter % $perColumnElement ==0 && $counter > 1){
                        echo '</div></div><div class="col-md-4"><div class="card-columns">';
                    }*/
                    if($counter==8 || $counter==15 || $counter==20){
                    // if($counter==6 || $counter==12 || $counter==19){
                        echo '</div></div><div class="col-md-4"><div class="card-columns">';
                    }
                    $counter++;

                }
               ?>

Here is the code for one of the drop down menus (this is from inspect element):

<div class="card-header card-header-primary mb-3">
                <a class="card-link cardCat collapsed" data-toggle="collapse" data-cat="1,2" href="#card_5" aria-expanded="false">
                  <div class="card-icon d-flex" style="align-items: center;">
                    <h4 class="title m-0">
                    <span class="cs-icon nm_icon"></span> <span class="cs-icon op_icon"></span> 
                    Menu 1 </h4>
                    <i class="fa fa-arrow-circle-down text-white ml-auto"></i>
                  </div>
                </a>
              </div>

I want to use local storage to do this, so I just added this code to the file:

localStorage.setItem('dropdownMenu', 'true');
localStorage.getItem('dropdownMenu');

This isn't working and I'm guessing its because I am not checking if it's set or not and checking its value. How can I check for this or fix it?

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