Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
283 views
in Technique[技术] by (71.8m points)

javascript - Show DIV or Section after redirecting to html page

I am having a problem with regards with showing DIV or section after redirecting to page, I am using magento custom page, so basically it is pure html.

Here's my code: 1st page:

1st page: <a href="otherpageurl"> 1st page </a>

second page:

<div id="secondpage_1st-div">
<h2>second page</h2>
<p>hello</p>
</div>

<div id="secondpage_2nd-div">
<h2>second page</h2>
<p>hello</p>
</div>

I need to show the div when I click the link on the first page. I'm using tab to show content of every div

Thank you

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Add a javascript to hide the div with id 'secondpage_2nd-div' in second page!

<script>
    element=document.getElementById("secondpage_2nd-div");
    element.style.display = 'none';           // Hide
    //element.style.display = 'block';          // Show
</script>

Else, there are many div in page, hide all the divs and show only one desired,

<script>
    var divs = ?document.getElementsByTagName("div");?
    for (var i = 0; i < divs.length; i++) {
      divs[i].style.display = 'none';        
    }
</script>

and then

<script>
    element=document.getElementById("secondpage_1st-div");
    element.style.display = 'block';           // show one div
</script

It totally depends on your requirement. Hope it helps!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...