问题
I have read all of your comments, but none of the solutions I read seem to work. I have a piece of Jquery code that gets some content from an external PHP script which updates a div in my application. After the new data is loaded, it doesn't have the Jquery Mobile styling. I've seen how some have used .page() or trigger("refresh"), etc... but none of that works to refresh an entire div. Here is my code and the portion of html in question:
function getcontent(pg) {
$("xyz").html("");
$.get("http://myscript.php", function(data) {
$("#xyz").html(data);
$("#xyz").page();
}
HTML:
<div id="xyz"></div>
Really, there's not much to this at all and I just can't figure this out. I had "some" success if I removed the wrapper div ("xyz") and just refreshed the individual elements' listview, buttons, etc., but that's a terribly clumsy method of handling this.
回答1:
One the page containing #xyz
, e.g. #mypage
, call
$('#mypage').trigger('pagecreate');
回答2:
I used the .page element on the list or div that has the refresh
$('ul.sessions-list *').page();
This refreshes everything in my sessions-list that was loaded, externally and corrects the css.
回答3:
try using
$("#page_id").trigger("create")
on the page that gets the content added to.
来源:https://stackoverflow.com/questions/10231122/how-do-i-refresh-the-css-for-a-div-loaded-with-external-content-in-jquery-mobile