[英]How do I get my page to remember user's last action?
We have a search form which allows users to search for items on the page. 我们有一个搜索表单,允许用户搜索页面上的项目。
There is also another form with checkboxes that allows users to refine their searches with the hope of reducing the number of search results. 还有另一种带有复选框的表格,允许用户优化搜索,以减少搜索结果的数量。
For instance, if I enter McCland on the search box and 13 results marching McCland are returned, I can click on Advanced search
and a bunch of checkboxes are rendered. 例如,如果我在搜索框上输入McCland并返回了进行Mcland的13个结果,则可以单击
Advanced search
然后显示一堆复选框。
I can then check "Street"
, "Road"
, "LandMarks"
, etc. I can then click search on McCland again. 然后,我可以检查
"Street"
, "Road"
, "LandMarks"
等。然后,我可以再次单击“搜索”。
This time, only addresses with Street or Road or LandMarks will be displayed if available. 这次,仅显示带有街道或道路或地标的地址(如果有)。
This works great. 这很好。
Then there is a Remember This Action
icon. 然后有一个“
Remember This Action
图标。
My biggest challenge so far is to allow users to click on this Remember This Action
icon and save their current results. 到目前为止,我最大的挑战是允许用户单击“
Remember This Action
图标并保存其当前结果。
This way, next time they visit the page, the results they searched for previously are presented to them unless they choose to search with another option. 这样,除非他们选择使用其他选项进行搜索,否则下次他们访问该页面时,会将以前搜索的结果显示给他们。
If they click on this Remember This Action
icon, they will be prompted with a message explaining that they are about to save their current Results. 如果他们单击此“
Remember This Action
图标,将提示他们一条消息,提示他们将要保存其当前结果。
They can click Yes to save or Cancel to not save. 他们可以单击“是”保存或单击“取消”不保存。
I suspect this will be done with cookies(jquery or Javascriot) but I am not sure how to do this. 我怀疑这将通过cookie(jquery或Javascriot)完成,但是我不确定如何做到这一点。
Any assistance is greatly appreciated. 非常感谢您的协助。
If you're looking for a jQuery solution you could use the JQuery Cookie Plugin: https://github.com/carhartl/jquery-cookie 如果您正在寻找jQuery解决方案,则可以使用JQuery Cookie插件: https : //github.com/carhartl/jquery-cookie
You're code might look something like this: 您的代码可能看起来像这样:
//Set the action
$.cookie('last_action', 'the_action');
//Get the action
var last_action = $.cookie('last_action');
if (typeof last_action != 'undefined') {
// show last action
} else {
//show default
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.