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
196 views
in Technique[技术] by (71.8m points)

javascript - With tabbed links inside another how to keep heading active?

Hard to explain in title. So I show image. (cant show image due to low reputation as new member)

  • link to image... i.gyazo.com/12243c1a729009d879a899327ca5c5c3.png
  • link to image... i.gyazo.com/602b8517d14a189f68f50758cb02a453.png

So i have 2 tabs, a header then tabs within the header element.

So you would click on league tables then option to view 3 league tables. But once click on the "div" tab the active class removes from the header eg "League tables".

I wasnt sure how to code this, I tried giving league tables/goalscorers a different class from the divs. But that didnt work.

Maybe I need to make 2 functions not one?

One function for headers and one for the Div tabs?

Here is my current code. One function to cover all.

function openDiv(evt, divName) {
     var i, tabcontent, tablinks, tablinks2;
     tabcontent = document.getElementsByClassName("tabcontent");
     for (i = 0; i < tabcontent.length; i++) {
     tabcontent[i].style.display = "none";
     }  
     tablinks = document.getElementsByClassName("tablinks");
     for (i = 0; i < tablinks.length; i++) {
     tablinks[i].className = tablinks[i].className.replace(" active", "");
    }
    document.getElementById(divName).style.display = "block";
    evt.currentTarget.className += " active";
    }
question from:https://stackoverflow.com/questions/65835492/with-tabbed-links-inside-another-how-to-keep-heading-active

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

1 Reply

0 votes
by (71.8m points)

I solved the issue.

I had to make 2 functions.

One for the headers, that would activate the submenus depending what heading was clicked on.

Then the function for the actual sub menu itself.


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

1.4m articles

1.4m replys

5 comments

57.0k users

...