1

複数の折りたたみ可能なページがいくつかあるページがあります。1つが拡張されたら、他のすべてを閉じたいと思います。動的に開いたり閉じたりするには、.trigger('expand')と.trigger('collapse')を使用する必要があることを読みました...しかし、折りたたみ可能なオブジェクトが実際に開かれたときにイベントを発生させるにはどうすればよいですか?

私はクリックイベントかもしれないと思った...-$('#myExpandable').click()行かない。私はバインドしようとしました.bind('expand', function() {} ); -行きません...そして私は.live('expand', function() {} );..すべてを無駄にしようとしました。

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

ありがとう!

4

1 に答える 1

2

要素のイベントにバインドしてから、残りの折りたたみ可能な要素でexpandイベントをトリガーできます。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/

于 2012-03-04T02:48:42.530 に答える