Hide/show some parts in the page
How can I do this:
In my page, I have a section like a welcome box. It contains title and content. I would want to allow users to hide and show the content when they click a button. And when they will refresh the page, the content w开发者_开发知识库ill be shown according to their previous action (to hide/show). How to do this that it will remember the last action without storing it(action performed) in the database?
Store the action in a cookie to keep the setting.
If it's possible that more than one person may use the same computer for the app you will want to append or prepend a user id or username to the name of the cookie.
Note that cookies do expire and can be deleted by the user. If it is a one time thing then you definitely want to use an ajax call to update a database value.
I would highly recommend that you look into jquery. all the tasks related to user interaction can be accomplished in just few lines. Even if your are using jQuery for the first time this shall take you 10 minutes to accomplish.
You can do two things.
Use cookies to maintain the status of the action and you can handle the action from server side with php or client side with javascript.
http://www.w3schools.com/js/js_cookies.asp
http://www.w3schools.com/php/php_cookies.asp
If you use javascript you can dynamically change the visibility of the relevant div with css using
display
css attribute.If you use PHP for this you can decide whether you send relevant part to the client's browser or not.
If you are targeting modern browsers with HTML5 support you can use local storage as well http://diveintohtml5.info/storage.html
精彩评论