Refresh popup content in jQuery mobile
In the jQuery mobile popup, enter some text and refresh the current page using changePage . After that open the open one, it will show up in the text box that I entered earlier. How to update the popup (Please don't suggest an empty textbox value).
Code:
localStorage.setItem("name","tiger");
$(document).on("click","#save",function(){
$("#openpopup").popup("close");
localStorage.setItem("name",$("#pText").val());
$.mobile.changePage("#page1",{
allowSamePageTransition : true,
transition : 'none',
});
});
$(document).on("pageshow","#page1",function(){
if(localStorage.getItem("name")){
$("#name").val(localStorage.getItem("name"));
}
});
Here is the FIddle
+3
Vini
source
to share
1 answer
To reset all form elements, eg. input
, select
, checkbox
Etc., you need to wrap them in form
. And then reset the form $("#formID")[0].reset()
when the popup is hidden.
$("#popupID").popup({
afterclose: function () {
$("#foo")[0].reset(); /* reset form */
}
}, "close");
Demo
+3
Omar
source
to share