问题
OK, after many hours of confusion I have discovered that calling page() on Jquery Mobile elements only works once.
What do I do if I want to update a form multiple times via AJAX?
回答1:
update
jQuery Mobile beta2 introduces a create event..trigger('create') applies JQM enhancements to an element and its children.
See: http://jquerymobiledictionary.pl/faq.html
You have to use it only once for an element. No exceptions yet.
if $('#container') is your element, and you replace its content with AJAX, then there are two things you can do:
- call
.page()on$('#container').children() - empty the container and create a div inside of it, and call
.page()on it.
The second option is better if your content needs to be wrapped (like a list) and I'd recommend it in general.
If you are using a listview or something take a look at .listview('refresh') or other dedicated methods.
回答2:
After several workarounds that did not meet my needs, I found this particular statement: remove or overwrite an existing div and call .page() on new div. This works best if content has to be reloaded / re-rendered / refreshed more than once.
来源:https://stackoverflow.com/questions/5362127/jquery-mobile-updating-a-form-more-than-once