2017-02-25 33 views

回答

1

您可以找到不倒塌的div:

$('#myc').on('collapsibleexpand', function(event, ui) { 
    $(this).find('div.ui-collapsible:not(.ui-collapsible-collapsed)')... 
}); 

或附加一個事件處理程序:

$('a.ui-collapsible-heading-toggle').on('tap click', function(e) { 
    .... 
}) 

的片段:

$(document).on("pagecreate", function() { 
 
    $('a.ui-collapsible-heading-toggle').on('tap click', function(e) { 
 
     if ($(this).closest('div.ui-collapsible').is('.ui-collapsible-collapsed')) { 
 
      console.log('tap click: ' + this.childNodes[0].textContent); 
 
     } 
 
    }) 
 

 
    $('#myc').on('collapsibleexpand', function(event, ui) { 
 
     var ele = $(this).find('div.ui-collapsible:not(.ui-collapsible-collapsed)'); 
 
     console.log('collapsibleexpand: ' + ele.find('a.ui-collapsible-heading-toggle').get(0).childNodes[0].textContent); 
 
    }); 
 

 
});
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" /> 
 
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script> 
 
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> 
 

 

 
<div data-role="content" id="myc"> 
 
    <div data-role="collapsible"> 
 
     <h3>I'm a header1</h3> 
 
     <p>I'm the collapsible content. By default I'm closed, but you can click the header to open me.</p> 
 
    </div> 
 
    <div data-role="collapsible"> 
 
     <h3>I'm a header2</h3> 
 
     <p>I'm the collapsible content. By default I'm closed, but you can click the header to open me.</p> 
 
    </div> 
 
</div>

+0

嗨!其實我想訪問這個擴展項目的內容。請介意解除您的解決方案嗎? –

+2

當在jQM中添加監聽器時,它應該被封裝在'pagecreate'而不是'.ready'中。 – Omar

+0

@Omar請介意幫助我訪問可摺疊項目的div的內容嗎? –