我的HTML是:
<ul id="nav"> <li><a class="current hoc" href="#spread1-anchor">Home</a> /</li> <li><a class="bgc" href="#spread2-anchor">Background</a> /</li> <li><a class="apc" href="#spread3-anchor">Approach</a> /</li> <li><a class="clc" href="#spread4-anchor">Client</a> /</li> <li><a class="sec" href="#spread5-anchor">Services</a> /</li> <li><a class="coc" href="#spread5-anchor">Contact</a></li> </ul>如果有帮助,我的网址是: Karls示例网站
And if it helps, my URL is: Karls Example site
使用上述jQuery代码 - 如何存储最后点击的链接用户刷新页面?我是一个初学者jQuery,即使我已经看到了答案,大多数是使用滑块或手风琴,所以太复杂,我不明白在这个阶段的学习限制! :)
Using the above jQuery code – how would I store the last clicked link when the user refreshes the page? Im a beginner with jQuery and even though I have seen answers out there, most of them are to do with sliders or accordions and so are much too complicated for me to understand at this stage of my learning curb! :)
有人可以帮助,也许显示如何实现代码或插件(如果需要的话,我在网上旅行时看到了一个cookies插件) / p>
Please could someone help and perhaps show how to implement the code or plugin too if one is required (I saw a cookies plugin on my travels around the net)
推荐答案您的连结是否有ID?如果是这样,只需将ID存储在Cookie中,点击。所以,像这样:
Do your links have IDs? If so, just store the ID in a cookie when clicked. So, something like this:
$('#nav a').click(function () { $.cookie('lastclicked',this.id); $('#nav a').removeClass('current'); $(this).addClass('current'); return false; });使用jQuery cookie插件减少了直接设置cookie的烦恼因素。在网页加载时,查找Cookie(请参阅文档),读取其值(如果存在),现在您知道最后一次点击的链接的ID。
Using the jQuery cookie plugin reduces the annoyance factor of setting the cookie directly. On page load, look for the cookie (see documentation), read its value if present, and now you know the ID of the last clicked link.
更多推荐
使用jQuery存储点击的链接状态?
发布评论