清除后退按钮上的表格? [英] Clear Form on Back Button?

查看:18
本文介绍了清除后退按钮上的表格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面,表单中有几个复选框,选中时,使用 jquery 从表中过滤出相应的信息.我的问题是以下情况:

I have a page with several check-boxes in a form, which when selected, filter corresponding info out of a table with jquery. My problem is the following scenario:

  1. 有人选中一个或多个框,隐藏表格中的行

  1. Someone checks one or more boxes, hiding rows from table

他们点击一个链接,转到另一个页面

They Click a link, going to another page

他们点击后退按钮.

此时,复选框仍处于选中状态(至少在 chrome 中),但所有表格行再次可见.

At this point, the check boxes are still checked (in chrome at least), but the all the table rows are visable again.

有什么想法吗?

推荐答案

如果您的目标是让他们回到他们离开之前的确切视图(表格行仍然隐藏):

这是网站的一个缺点(或优点):它是无状态的,尤其是在涉及客户端操作时.

Such is a disadvantage (or advantage) of a website: it's stateless, particularly when it comes to client-side manipulation.

您需要做的是将应用程序状态存储在 URL 哈希标记中,以便当用户使用他们的后退按钮时,您可以检索状态"并重建他们的视图.

What you'll need to do is store the application state in the URL hash tag so that when the user uses their back button, you can retrieve the "state" and reconstruct their view.

这是另一个问题,其答案可能对您有所帮助:jquery javascript:添加使用标签返回浏览器历史记录?

Here's another question whose answer might help you: jquery javascript: adding browser history back with hashtag?

如果您的目标是将页面恢复到初始状态:

只需在页面加载时重置所有复选框:

Just reset all the checkboxes on page load:

$('input:checkbox').prop('checked', false);

-或-

重置整个表单:

$(':input','#myform')
 .not(':button, :submit, :reset, :hidden')
 .val('')
 .prop('checked', false)
 .prop('selected', false);

这篇关于清除后退按钮上的表格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆