我有一个问题,我无法以正确的方式解决。
我有一个小提琴,说明了我的问题:
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
但是我无法创建选择器来执行此任务。
答案 0 :(得分: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);
});
});