问题
With help of "@Dimitar Dimitrov" I have create this javascript that changes values after click on link. Here is JSFiddle link: http://jsfiddle.net/3uqF2/19/
Here is code of function:
$(document).ready(function () {
$(".my-link").on("click", function() {
$(".status").hide();
var linkId = $(this).data("id");
$("." + linkId).show();
});
});
My Question is, how can I upgrade it, so when I refresh page or click on post (e.g. search button), my value that I click (e.g. "Eng", watch link of Fiddle) saves, so when I again click on refresh or post, this link would stay until I click another one. Now when I click refresh or post it always return to first link "Slo" (watch link of Fiddle).
!Note: I have put this code in my _Layout.cshtml so I can use it on all pages.
Thanks for help.
回答1:
try saving it in a cookie :
$(document).ready(function () {
//getting the value of the cookie
if(document.cookie!=""){
$(".status").hide();
var linkId = document.cookie;
$("." + linkId).show();
}
$(".my-link").on("click", function() {
$(".status").hide();
var linkId = $(this).data("id");
//setting the value of the cookie
document.cookie=linkId;
$("." + linkId).show();
});
});
回答2:
You can perform an action when the user is leaving the page by binding a remove call on <body/>:
$('body').bind('remove', function(event) {
$.get('/api/leaving_page');
});
来源:https://stackoverflow.com/questions/24927981/how-can-i-upgrade-my-jquery-that-will-save-last-function-when-post-or-refresh-pa