Reset checkbox checked state go back from history

后端 未结 4 493
余生分开走
余生分开走 2021-01-13 01:15

In the following example, I use checkbox for making a pure CSS dropdown navigation, also available in this jsFiddle example.

Open that fiddle, click

4条回答
  •  -上瘾入骨i
    2021-01-13 01:24

    Further to the other comments, if you are writing an AJAX driven page that uses pushState/replaceState, and the back button would not actually reload a page (i.e. no HTTP request), you can listen for the popState event and clear the checkbox.

    window.onpopstate = function(event) {
       $("#m").prop('checked',false );
    };
    

    It's a HTML 5 feature that's not fully supported across all browsers (although support is pretty good)

    https://developer.mozilla.org/en-US/docs/Web/Events/popstate

    Other options would be to use libraries like history.js, jquery-bbq, sammyjs, and so on.

提交回复
热议问题