简体   繁体   English

单击特定的<a>href链接一次</a>后,在整个网站上永久显示隐藏的div

[英]Show hidden div permanently throughout website after clicking on a specific <a> href link once

I found this link of a question like the one I have, the thing is that the solution they give is for clicking any div in the html, and I need something like, when i click on the first div, the second div showing and when I press on the second div, the third div is showing. 我发现了这个问题的链接 ,就像我遇到的那样,问题是他们提供的解决方案是单击html中的任何div,我需要类似的内容,当我单击第一个div时,第二个div显示何时我按第二个div,显示第三个div。 And I need to keep if in localstorage... This is my HTML code: 而且我需要保留在本地存储中...这是我的HTML代码:

<div id='btn1' class="col-lg-4"">
<a id="tema_1 " href="tema.html"><img id="img_tema1" class="img-circle" src="../assets/img/primer_tema.gif" alt="Generic placeholder image" width="140" height="140"></a>
<h2>Tema 1</h2>
</div><!-- /.col-lg-4 -->

<div class="col-lg-4-2">
<a href=""><img id="img_tema2" class="img-circle2" src="../assets/img/segundo_tema.gif" alt="Generic placeholder image" width="140" height="140"></a>
<h2>Tema 2</h2>  
</div><!-- /.col-lg-4-2 -->

<div class="col-lg-4-3">
<a href="tema_3.html"><img id="img_tema3" class="img-circle3" src="../assets/img/tercer_tema.gif" alt="Generic placeholder image" width="140" height="140"></a>
<h2>Tema 3</h2>
</div><!-- /.col-lg-4-3 --

And this is the example of Jquery code that i use: 这是我使用的Jquery代码的示例:

var hide2 = localStorage[location] ? false : true;
var hidden2 = document.querySelector('.col-lg-4-2');

if(hide2) {
    hidden2.style.display = 'none';
    document.onclick = function() {
        localStorage[location] = true;
        hidden2.style.display = '';
        document.onclick = '';
        console.log('click');
    }
}

But as I say... it makes that any div that I click, shows the Tema 2, and I need that the only div that can show the Tema 2 is the Tema 1 Div. 但是,正如我所说的那样,它会使我单击的任何div都显示Tema 2,并且我需要能够显示Tema 2的唯一div是Tema 1 Div。

Excuse my bad English but my mother language is Spanish. 对不起,我的英语不好,但我的母语是西班牙语。

Thank you for any help. 感谢您的任何帮助。

I think this might be solved using simple jQuery. 我认为可以使用简单的jQuery解决此问题。 I've used the example specified at: Previous Similar question and changed it so it will fit your code. 我使用了以下示例中指定的示例: 上一个类似的问题 ,并将其更改为适合您的代码。 It currently works which is fine but I might wanna work around it if you don't like my solution. 它目前可以正常工作,但是如果您不喜欢我的解决方案,我可能想解决它。

 $(function () {
    var showLittleHeader = localStorage.getItem('#second-img');
    if (showLittleHeader) {
        $('#second-img').show();
    }
    $('#first-img').on('click', function () {
        localStorage.setItem('#second-img', 1);
        $('#second-img').show();
    });

});

$(function () {
    var showLittleHeader = localStorage.getItem('#third-img');
    if (showLittleHeader) {
        $('#third-img').show();
    }
    $('#second-img').on('click', function () {
        localStorage.setItem('#third-img', 1);
        $('#third-img').show();
    });

});

Look at this JS Fiddle and see if it does the job for you: 查看此JS Fiddle,看看它是否对您有用:

Updated Solution with Local Storage 更新的本地存储解决方案

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

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