处理 jQuery 菜单包含在多个页面上的方法
这不是一个具体的代码问题,而更多的是一个概念问题。我正在尝试找出解决这个问题的方向。
这是网站 testsite
现在,当您将鼠标悬停在内部上时然后单击Mastersuite,它会将您带到主套件的页面,其中包括通过 SSI 的导航栏,但是当页面加载时,导航菜单会重置,就像您第一次加载索引时一样。我想让菜单加载到单击链接时的状态。我还希望所有页面上的导航栏都只有一个 HTML 文件。
最通用、最干净且可更新的方法是什么?
我的想法
- 是使用查询字符串来告诉导航栏脚本查看者正在
- 使用该小节页面中的某种 JavaScript(即:mastersuite.html 或 bathrooms.html)告诉导航栏脚本用户所在的页面
This isn't a specific code question, but more of a conceptual question. I'm trying to figure out which direction I should go in solving this problem.
Here is the site testsite
Right now when you hover over interior and click Mastersuite, it takes you to a page for the master suite, which includes the navbar through SSI, but when the page loads the navigation menu is reset just like when you first load the index. I want to have the menu load in the state it was in when the link was clicked. I also want to have only one HTML file for the navbar on ALL pages.
What would be the most universal, clean, and update-able way of doing this?
My ideas
- use query string to tell navbar script which section the viewer is in
- use some kind of JavaScript within the subsection page (ie:mastersuite.html or bathrooms.html) to tell the navbar script what page the user is on
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一个选项是对于将您带到另一个页面的每个链接,将散列设置为其所属的部分 ID。
然后在每个页面上,当页面加载时,获取哈希值,并将其用作选择器来触发显示该类别的事件。
One option is for each of the links that takes you to another page, set the hash to the section ID to which it belongs.
Then on each page, when the page loads, get the hash value, and use it as a selector to fire the event that shows that category.
好吧,这就是我所做的,似乎是一个不错的解决方案。
在部分页面(即: Bathrooms.shtml 或 mastersuite.shtml)上,我使用了此
“section”的值是该页面所在的部分。
然后在我的导航栏脚本中我使用了这个
我喜欢这个因为它不需要查询字符串或锚点,而且它非常简单
Ok so this is what i did and seems like a nice solution.
on the section page (ie: bathrooms.shtml or mastersuite.shtml) i used this
the value of "section" is the section that that the page is under.
and then on my navbar script i used this
I like this because it requires no querystring or anchors, and it is ridiculously simple