javascript - How do I persist the checkbox status after click event/jQuery/ajax call -
i have following event code reloads code section on page. problem that, if check box checked, can't find way re-check after reload.
jquery(this.el).find('.view_all_future_filter').click(function () { todonote.view_all_future_filter = jquery(this).prop('value'); _this.parent.reload(); })
i tried following, check box keeps being reset unchecked:
if(this.view_all_future_filter == "on") { this.query_string += '&view_all_future_filter=' + this.view_all_future_filter; var show_state = "checked"; } else { var show_state = ""; } this.load(); jquery('#view_all_future_filter').prop('checked', show_state);
any appreciated!
you can use sessionstorage save data , after reload content:
if (window.sessionstorage) { var checkedstate = jquery('#view_all_future_filter').attr('checked'); sessionstorage.setitem("somecheckboxstate", checkedstate); }
and when content loaded page:
if (window.sessionstorage) { var checkedstate = sessionstorage.setitem("somecheckboxstate"); jquery('#view_all_future_filter').attr('checked', checkedstate); }
note: if using jquery 1.6+
must change attr
prop
boolean properties checked
, disabled
, etc.
Comments
Post a Comment