javascript - After clicking nav, using JS to add color, how can the changed color be maintained after the page jumps?
ringa_lee2017-05-16 13:21:25
0
12
1653
Each navigation page is the same piece of HTML linked through the background tag. After clicking the navigation, I change the color through js, but when I click to jump to a page, the color changed by js becomes invalid. How to solve this problem?
Save what the heck, I entered page a from the navigation bar, closed it, and then entered page b from the address bar. Will you highlight page a for me at this time? Write a parsing function common to all pages, and directly use the nav address to match the href
I’ll answer it myself. It doesn’t need to be as complicated as what you wrote. Just add a piece of CSS to each page
Save what the heck, I entered page a from the navigation bar, closed it, and then entered page b from the address bar. Will you highlight page a for me at this time?
Write a parsing function common to all pages, and directly use the nav address to match the href
Tell me the idea and add js judgment to each page
A few ways:
The navigation bar has its own iframe;
Use sessionStorage / localStorage to save state;
Jump page with URL parameters&active =xxx;
Using spa does not really jump to the page;
Looking at the answerer’s question, I guess 2 or 3 are more suitable
There is no need to use JS, just use the css class name. Add a class name to each nav and put it in the css file of this nav
Save it locally
The background can determine which page the current page is and then add a category. This is more convenient.
Save locally, and when you enter the page again, read the cache and make a judgment
Save status to cookie.
Save to session, but this requires the cooperation of back-end development.
Add active to the li class, set the font color of active, and dynamically add classes to each li!