使用jQuery存储点击的链接状态?

编程入门 行业动态 更新时间:2024-10-21 03:15:29
本文介绍了使用jQuery存储点击的链接状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 $('#nav a').click(function () { $('#nav a').removeClass('current'); $(this).addClass('current'); return false; });

我的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存储点击的链接状态?

本文发布于:2023-10-13 10:14:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1487667.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:状态   链接   jQuery

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!