How to toggle between two divs and remain on the chosen div after saving/refreshing the page?
I saw this script here in stackoverflow to toggle between two divs (it's from this page):
http://jsfiddle.net/PauWy/1/
It's working but is there a way to tweak the script so that it stays on that toggl开发者_JAVA百科ed DIV, even after refreshing/saving the page?
Our page allows us to choose between uploading a photo or a video. If the user chooses photo, then when that person returns to that same page, it should show the "upload photo" but if the user chooses video, the page should be automatically toggled to "upload video." Right now, the default is always "upload photo" even if the user chose to toggle/use the "upload video" section.
You need persistance, and one way to achieve this is via cookies.
Use the jQuery Cookie Plugin.
To save a cookie, all you need to do is:
$.cookie("key", "value");
And to retrieve:
$.cookie("key");
And to delete:
$.cookie("key", null);
So your logic would be:
if cookieValue == "thisDiv"
showDiv1
else
showDiv2
end
Store the choice in a cookie and check that cookie when you load the page.
精彩评论