问题
After dynamically updating a header tags text for an existing collapsible element, the styling disappears, even though im calling .collapsible({refresh: true}) after updating.
jsFiddle: http://jsfiddle.net/RAxn5/ (click the 'Break it' link to see what i mean).
HTML:
<div id="set" data-role="collapsible-set">
<div data-role="collapsible" id="set1" data-collapsed="false">
<h2 class="section_title">Section 1</h2>
<ul data-role="listview">
<li><a href="#"><h3>item 1</h3></a></li>
<li><a href="#"><h3>item 2</h3></a></li>
<li><a href="#"><h3>item 3</h3></a></li>
</ul>
</div>
</div>
<a href="#" id="break">Break it</a>
JS:
$('#break').click(function() {
$('#set1 h2.section_title').text('Now my style is gone!');
$('#set1').collapsible({refresh: true});
});
Thanks in advance.
回答1:
Add it to span.ui-btn-text not to h2.
Demo
$('#set1 span.ui-btn-text').text('Now my style is gone!');
回答2:
An easy solution (although a bit hacky) is to find the span that the button sets up and change that rather than the parent id.
$('#set1 h2.section_title').find('.ui-btn-text').text('Now my style is gone!');
Here is the JSFiddle for it.
来源:https://stackoverflow.com/questions/16589979/jquery-mobile-dynamically-updating-collapsible-heading-causes-loss-of-styling