简体   繁体   English

单击按钮后,切换到其他页面并显示隐藏的内容

[英]After button clicked, change to different page and show hidden content

I have some "Learn More" links on my Home page, all of which correspond to different sections of content that is on the More Info page. 我的主页上有一些“了解更多”链接,所有这些链接都对应于“更多信息”页面上内容的不同部分。 These different sections of content are all hidden using display: none. 内容的这些不同部分都使用display隐藏:无。

What I'm wondering is if there's a way to make it so that when I click a particular "Learn More" link, the user will be sent to the More Info page, and the section of content corresponding to the Learn More link they clicked will be shown. 我想知道的是,是否有办法做到这一点,以便当我单击特定的“了解更多”链接时,用户将被转到“更多信息”页面,并且与他们单击的“了解更多”链接相对应的内容部分将显示。

I can't think of a way to achieve this, but I'm hoping it will be possible, perhaps using JavaScript. 我想不出一种方法来实现这一目标,但我希望有可能实现,也许使用JavaScript。

EDIT: The code I currently have is nothing special. 编辑:我目前拥有的代码没什么特别的。 Four <a> links on the Home page, then on the More Info page, four divs that are all initially hidden using display: none . 主页上的四个<a>链接,然后在“更多信息”页面上,最初使用display: none隐藏了四个div display: none

该解决方案最终变得非常简单,我做了此问题的最高答案中所述的操作: 获取URL哈希位置,并在jQuery中使用它

 <a href="javascript:showContent('id_here');">Learn more</a>

 <script>
    function showContent(id) {
        $("#"+id).show();
    }
 </script>

I think it is possible.You can take the information on a div,and then you click "Learn more",show the div. 我认为这是可能的。您可以在div上获取信息,然后单击“了解更多”,显示div。 In this way,you even needn't a hyperlink,just a click event,like the code upstairs.Of course,this div was hidden before. 这样,您甚至不需要超链接,只需单击事件,就像楼上的代码一样。当然,此div之前是隐藏的。

One way you can achieve this would be to add a hash to that link with the id of the section you want to show, like this: <a href="/moreinfo#section-id">Learn More</a> . 实现此目的的一种方法是,向该链接添加要显示的部分ID的哈希,例如: <a href="/moreinfo#section-id">Learn More</a> Then just check for it in window.location.hash on the /moreinfo page and show the div. 然后只需在/ moreinfo页面上的window.location.hash检查它并显示div。

You have to do it this way: try to use named anchors . 您必须采用这种方式: try to use named anchors

first: 第一:

<a href="your-page-url-here#section-3">Learn More</a>

when use clicks this link user will navigate to particular page with different sections. 当使用单击时,此链接用户将导航到具有不同部分的特定页面。

second: 第二:

on this page suppose you want to show the 3rd section: 在此页面上,假设您要显示第3部分:

 .....
 <a name='section-3'></a>
 <h1>Your section-3</h1>

In your case divs are hidden then use js or jQuery for this: 在您的情况下, divs are hidden然后为此使用js或jQuery:

As you will get a hash in the location url then use .substr()' and .indexOf()` javascript methods. 由于您将在位置网址中获得哈希值,因此请使用.substr()' and .indexOf()`JavaScript方法。

try to put this script on those page where you are having your hidden divs 尝试put this script放在where you are having your hidden divs页面where you are having your hidden divs

$(function(){
   var url = window.location.href;
   var obj = url.substr(url.indexOf('#'));
   $(obj).show();
});

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

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