JQuery-Mobile可折叠扩展/折叠事件
除了标题的onclick
事件之外,有没有人知道任何其他方法来捕获扩展或折叠标有data-role="collapsible"
的组件的事件?
编辑:我想要某种事件,它也将提供有关组件的扩展/折叠状态的信息。
collapsible
块有自定义事件。 您可以绑定到expand
和collapse
事件:
$('#my-collapsible').bind('expand', function () { alert('Expanded'); }).bind('collapse', function () { alert('Collapsed'); });
这是一个jsfiddle: http : //jsfiddle.net/6txWy/
在jQuery Mobile 1.4中,有collapsiblecollapse和collapsibleexpand事件。 https://api.jquerymobile.com/collapsible/#event-collapse
$( ".selector" ).on( "collapsiblecollapse", function( event, ui ) {} );
您可以绑定任何所需的事件,例如:
演示:
JS
$("div:jqmData(role='collapsible')").each(function(){ bindEventTouch($(this)); }); function bindEventTouch(element) { element.bind('tap', function(event, ui) { if(element.hasClass('ui-collapsible-collapsed')) { alert(element.attr('id')+' is closed'); } else { alert(element.attr('id')+' is open'); } }); }
HTML
Header #1
I'm Header #1
Header #2
I'm Header #2
我不认为还有另一种方法可以做到这一点。 我不相信你可以在这种情况下使用animationComplete
,如下所述:
http://jquerymobile.com/test/docs/api/events.html
也许您可以对特定元素使用某些类更改,这实际上并不比绑定标题的onclick事件更好。
您可以尝试jQuery移动点击事件。 我没有亲自使用它,但我听说它类似于mousedown
事件处理程序。 如果你详细介绍了为什么onclick不能正常工作,我们可以帮助你多一点。