Clear Form on Back Button?

后端 未结 4 961
太阳男子
太阳男子 2020-12-16 04:46

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:

4条回答
  •  [愿得一人]
    2020-12-16 05:15

    If your objective is to bring them back to the exact view they had before they left (table rows are still hidden):

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

    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.

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

    If your objective is to return the page back to its initial state:

    Just reset all the checkboxes on page load:

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

    -or-

    Reset the entire form:

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

提交回复
热议问题