jQuery mobile: Dynamically updating collapsible heading causes loss of styling

天涯浪子 提交于 2019-12-12 10:02:27

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!