I am trying to include a collapsible widget in jquery mobile. The content is dynamic so I am using a markup to do this, but just for illustration I have included default text. The following code just brings no widget but just the text appears, the styling of the widget doesn't appear. Here is my javascript

  description_markup += '<h4>Description heading</h4><p>'+description+'</p>'; 

   $('#Desc').empty().append(description_markup);

HTML

 <div data-role="content" class= "ui-content" data-theme="d">
       <p id="message"/>
       <div id ="videoDisplay"></div>
       <div id ="vidLikeDislikebutton"></div>
        <div id ="Desc" data-role="collapsible"
             data-theme="b" data-content-theme="b"
             class="ui-collapsible ui-collapsible-inset
                    ui-collapsible-themed-content">
       </div>
</div><!-- /content -->

when I put the Desc div outside the content div, the text appears with a black background.

Please help

有帮助吗?

解决方案

jQuery Mobile team is still working on creating methods for collapsible such as refresh. Unfortunately, collapsible doesn't accept any method now. Thus, replacing current collapsible with a new one is the only way.

Demo

var description_markup = '<div data-role="collapsible" id="Desc" data-theme="e" data-content-theme="b"><h3>Description heading</h3><p>collapsible</p></div>';
$('#Desc').replaceWith(description_markup);
$('#Desc').collapsible();

If collapsible is enhanced and you don't want to replace it, you still can do modifications.

$('#Desc .ui-btn-text').text('new header');
$('#Desc .ui-collapsible-content').append('<p>new content</p>');

Inserting widgets inside collapsible requires .trigger('create') to enhance widget markup

$('#Desc .ui-collapsible-content').append('<ul data-role="listview"><li><a>link</a></li><li><a>link</a></li></ul>').trigger('create');
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top