简体   繁体   English

如何创建指向显示/隐藏javascript隐藏的内容的链接?

[英]How do you create links to content hidden by show/hide javascript?

I would like to create links to content that is hidden by a show/hide java script. 我想创建指向显示/隐藏Java脚本隐藏的内容的链接。 There are three divs within each hidden content with videos and text to which I would like create links; 每个隐藏内容中都有三个div,其中包含我要创建链接的视频和文本; eg, create a link to the "example" div shown in the code below. 例如,创建指向以下代码中所示的“ example” div的链接。 It doesn't have to be linked directly to each div. 它不必直接链接到每个div。 Creating a link destination above the div would be even better. 在div上方创建链接目标会更好。 I hope my question makes sense. 我希望我的问题有道理。

The code I am using for the show/hide works perfectly. 我用于显示/隐藏的代码可以完美地工作。 This is a generic version of that code: 这是该代码的通用版本:

HTML HTML

<p>***Visible content***
<a href="#" id="example-show" class="showLink" 
onclick="showHide('example');return false;">See more.</a>
</p>
<div id="example" class="more">
    <p>***Hidden content***</p>
    <p><a href="#" id="example-hide" class="hideLink" 
    onclick="showHide('example');return false;">Hide this content.</a></p>

CSS CSS

.more {
display: none;
border-top: 1px solid #666;
border-bottom: 1px solid #666; 
}
a.showLink, a.hideLink 
{
text-decoration: none;
color: #36f;
padding-left: 8px;
background: transparent url('down.gif') no-repeat left; 
}
a.hideLink {
background: transparent url('up.gif') no-repeat left; 
}
a.showLink:hover, a.hideLink:hover {
border-bottom: 1px dotted #36f; 
}

JavaScript JavaScript的

function showHide(shID) {
    if (document.getElementById(shID)) {
        if (document.getElementById(shID+'-show').style.display != 'none') {
            document.getElementById(shID+'-show').style.display = 'none';
            document.getElementById(shID).style.display = 'block';
        }
        else {
            document.getElementById(shID+'-show').style.display = 'inline';
            document.getElementById(shID).style.display = 'none';
        }
    }
}

Hoping that I understand your question. 希望我理解你的问题。 Study the example below 研究下面的例子

HTML HTML

 $(document).ready(function() { $('li').click(function () { $('.content:visible').hide(); // hides the visible content before $('.content').eq($(this).index()).show(); // shows the corresponding content }); }); 
 li { display: inline; text-transform: uppercase; font-family: calibri; height: 24px; } .content { font-size: 60px; color: red; } .content:not(:first-of-type) { display: none; /* Hides all but the first .content div */ } li a { padding: 0 15px 0 15px; text-decoration: none; line-height: 24px; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <ul> <li> <a href="#">One</a></li> <li><a href="#">Two</a></li> <li><a href="#">Three</a></li> <li><a href="#">Four</a></li> </ul> <div class="content"> Content One</div> <div class="content"> Content Two</div> <div class="content"> Content Three</div> <div class="content"> Content Four</div> 

Note: Had to put this together to help you understand how you can achieve what you want, so you have to make necessary changes to get it to work for you. 注意:必须将它们放在一起以帮助您了解如何实现所需的功能,因此必须进行必要的更改才能使其适合您的工作。

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

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