2012-03-04 8 views
1

複数の折り畳みがあるページがあります。 1つが展開されるとき、私は他のすべてを閉じたいです。私は、.trigger( 'expand')と.trigger( 'collapse')を動的に開いたり閉じたりする必要があることを読んでいます...しかし、折り畳みが実際に開いたときにイベントを発生させるにはどうすればいいですか?JQモバイル折りたたみ式 - 折りたたみ時に何かしたいと思っています。それを打つ方法を見つけてください。

私はMAYBEのクリックイベントを考えました... $('#myExpandable').click() - いいえ。 私はバインドしようとしました.bind('expand', function() {}); - いいえ... そして、私は.live('expand', function() {});を試してみました。

誰かがここで私を手がかりにすることはできますか?

ありがとうございます!

答えて

2

あなたは、要素のexpandイベントに結合し、その後、collaspiblesの残りの部分にcollapseイベントをトリガすることができます:ここで

//since we don't know when the page will be injected into the DOM, 
//we can bind to it's elements once it's been added to the DOM and is about to be initialized 
$(document).delegate('#my-page-id', 'pageinit', function() { 

    //cache each of the collapsible elements in a variable 
    var $collapse = $(this).find('[data-role="collapsible"]'); 

    //bind to each collapsible's `expand` event 
    $collapse.bind('expand', function() { 

     //when a collapsible is expanded, collapse all the others on this page 
     $collapse.not(this).trigger('collapse'); 

    }); 
});​ 

はデモです:http://jsfiddle.net/FhZVn/

+0

恐ろしいありがとうございました!!!私はこのドキュメントを見たことがありません。 –

関連する問題