页面刷新后丢失点击信息 [英] Losing click information after page refresh
问题描述
我为NavBar提出了以下建议.好吧,在使用F5刷新当前页面后,我丢失了点击信息,根据NavBar的所有操作都恢复为默认设置,就像您从未点击过链接:/
I came up with the following for my NavBar. Well, after refreshing the current page using F5 I am losing my click information, everything according to my NavBar falls back to default, like u've never clicked on a link :/
<script>
"use-strict";
$(document).ready(function()
{
/*
$(".default").show();
*/
$("#navSalon>ul>li a").click(function()
{
$("#navSalon>ul>li a").next().hide();
$(this).next().show();
});
$("#navSalon>ul>li a").click(function()
{
$("#navSalon>ul>li a").children().attr("src", "dot1.png");
$(this).children().attr("src", "dot0.png");
});
});
</script>
推荐答案
因为HTTP是无状态的.刷新页面时,这是一个新的HTTP Get请求,将请求发送到服务器并获取结果.
Because HTTP is stateless. When you refresh the page, It is a new HTTP Get request going to the server and getting the results.
如果要保留所做的更改,则需要将其保存在持久的介质中.您可以考虑以下
If you want to keep the changes you made, you need to keep that in a persistent medium. You may consider the following
1)数据库:将您的更改存储在数据库中,并在其他请求上再次加载
1) Database: Store your changes in database and load it again on further requests
2)会话:如果使用服务器端语言,则将更改存储在Session变量中.生命周期一直到用户会话结束为止.
2) Session : Store your changes in Session variable , If you work with a server side language. The life time of this is till the user session ends.
3)Cookie :将其存储在浏览器Cookie中
3) Cookies : Store these in browser cookies
这篇关于页面刷新后丢失点击信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!