如何通过单击按钮切换jQuery Mobile Accordion?

时间:2011-06-29 15:28:21

标签: jquery-mobile

创建jQuery Mobile Accordion时,如何在单击按钮时打开手风琴的一部分?

当用户点击搜索按钮时,我想将结果加载到第二个面板的列表中,折叠第一个面板并展开第二个面板。

<div data-role="collapsible-set">

    <div id="filterContainer" data-role="collapsible" data-collapsed="false">
        <h3>Filters</h3>
        <p>controls to pick options</p>
        <a href="#" data-role="button" id="search">Search</a>
    </div>

    <div id="resultsContainer" data-role="collapsible">
        <h3>Results</h3>
        <p>list of results</p>
    </div>

<div>

1 个答案:

答案 0 :(得分:5)

直播示例:

HTML:

<div data-role="page" id="home" class="type-home"> 
    <div data-role="content">
        <div data-role="collapsible-set">

            <div id="filterContainer" data-role="collapsible" data-collapsed="false">
                <h3>Filters</h3>
                <p>controls to pick options</p>
                <!-- Either button syntax works -->
                <!-- <a href="#" data-role="button" id="search">Search</a> -->
                <input type="button" value="Search" id="search"/>
            </div>

            <div id="resultsContainer" data-role="collapsible" data-collapsed="true">
                <h3>Results</h3>
                <p>list of results</p>
            </div>

        <div>
    </div>
</div>

JS:

$('#search').click(function() {
    $('#resultsContainer').trigger('expand');
});