0

我有一个问题,我无法以看起来正确的方式解决。

我有一个小提琴来说明我的问题:

http://jsfiddle.net/adamsurfari/qsP52/

<body>
<div data-role="page" id="index">
    <div data-theme="a" data-role="header">
        <a href="#" class="ui-btn-left" data-icon="back">BACK</a>
        <h3>
            You Selected
        </h3>
    </div>

    <div data-role="content" id="test-main-container">
        <div data-role="collapsible-set" data-inset="false">

            <div data-role="collapsible" data-theme="b" data-content-theme="d" data-inset="false">
                <h3>FROG</h3>
                <ul data-role="listview">
                    <li><a href="#">BULL FROG</a></li>
                </ul>
            </div><!-- /collapsible -->
            <div data-role="collapsible" data-theme="b" data-content-theme="d" data-inset="false">
                <h3>TOAD</h3>
                <ul data-role="listview">
                    <li><a href="#">FAT</a></li>
                </ul>
            </div><!-- /collapsible -->
            <div data-role="collapsible" data-theme="b" data-content-theme="d" data-inset="false">
                <h3>REPTILE</h3>
                <ul data-role="listview">
                    <li><a href="#">Aardvark</a></li>
                    <li><a href="#">Alligator</a></li>
                    <li><a href="#">Ant</a></li>
                    <li><a href="#">Bear</a></li>
                    <li><a href="#">Beaver</a></li>
                    <li><a href="#">Cougar</a></li>
                    <li><a href="#">Dingo</a></li>
                </ul>
            </div><!-- /collapsible -->

        </div>
    </div>
</div>
</body>

我想做的是保存手风琴家庭和手风琴菜单的选项。例如,如果我选择选项 BULL FROG

我会有 var selectedAnimal = BULL FROG, selectedFamily = FROG

但是,我无法创建选择器来执行此任务。

4

1 回答 1

3

这是一个工作示例:http: //jsfiddle.net/Gajotres/4uzKp/

$(document).on('pagebeforeshow', '#index', function(){       
    $(document).on('click', '[data-role="listview"] li', function(){       
        var selectedAnimal = $(this).find('.ui-btn-text a').text();
        var family = $(this).parent().parent().parent().find('.ui-btn-text').first();
        family.find('span').remove();
        family = family.text();
        alert("Selected animal = " + selectedAnimal + ", selected family = " + family);
    });
});
于 2013-04-10T15:03:31.327 回答