我有几个页面,上面有多个可折叠的内容。当一个被扩展时,我想关闭所有其他的。我已经读到我需要使用.trick('expand')和.tricker('collapse')来动态打开和关闭。。。但是,当一个可折叠的东西被打开时,我该如何启动一个活动?
我想也许是点击事件。。。$('#myExpandable').click()
—禁止。我试着绑定.bind('expand', function() {} );
——不通过。。。我试过.live('expand', function() {} );
。。一切都无济于事。
有人能在这里给我提供线索吗?
谢谢!
您可以绑定到元素的expand
事件,然后在其他collapsibles上触发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/