Jquerymobile does not support correct rendering after dynamically adding elements _ jquery

Source: Internet
Author: User
This article mainly introduces how to solve the problem of incorrect rendering after jquerymobile dynamically adds elements. For more information, see, I hope to help you solve some problems that cannot be correctly rendered after jquerymobile dynamically adds elements:
Listview: Add jq (". detail"). listview ("refresh ");
P or others: Add. trigger ("create ");
========================================================== ====================================

Jqm inserts jqm attributes and classes in each element based on data-xxx during page initialization. After page initialization, if an element is inserted dynamically, it is often ugly because the jqm style is not inserted. This can be viewed using development tools in the browser. Some elements have many more classes, and the dynamically inserted element code is what you wrote.

To make the dynamically inserted element have a jqm style, you can trigger the create event on the jqm object:

The Code is as follows:


$ (Selector). trigger ('create ');


The create event applies to a wide range of elements (raw markup ?), For example, to insert a button

The Code is as follows:


$ ('Dy click'). appendTo ('# content'). trigger ('create ');


Some objects provide the refresh method, such as listview and flip toggle. The difference between the refresh method and the create method is that the refresh method must be applied to an existing object, as shown in figure

$ ('Ul '). listview ('refresh'), and refresh only updates the newly added elements. For example, the latest append elements in listview are updated, and the original elements remain unchanged. (I do not know whether it is understood or not. Some of them are not tested. Original http://stackoverflow.com/questions/7663078/jquery-mobile-page-refresh-mechanism

Do not use the jqm style:

If you do not want jqm to automatically initialize your elements, there are two methods. Add the data-role = "none" attribute, or configure the keepNative option in the mobileinit event.

The Code is as follows:


$ (Document). bind ('leleinit ', function (){
$. Mobile. page. prototype. options. keepNative = "select, input. foo, textarea. bar ";
});

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.