Forcing jQuery Mobile to re-evaluate styles/theme on dynamically inserted content

前端 未结 7 985
感情败类
感情败类 2020-11-28 04:40

Objective: Load HTML content via $.ajax, insert it into the DOM, have jQuery Mobile apply theme styles to it.

Problem:

7条回答
  •  鱼传尺愫
    2020-11-28 05:31

    In jQuery Mobile Framework alpha4.1 and earlier this was done by using the .page() method.

    Example to show there's not much of a difference:

    $( ... lots of HTML ...).appendTo(".ui-content").page();
    

    More info: http://jquerymobiledictionary.dyndns.org/faq.html

    Why the new way (see T. Stone's answer) was introduced? .page() was written with an assumprion that the DOM element was not enhanced before.

    For the sake of decoupling tje jQuery Mobile team introduces event-driven enhancement that will not only allow triggering the event, but also will make creating new widgets for new data-roles possible without modifying the code of JQM's .page method.

提交回复
热议问题