使用单独的按钮在 JQUERY Mobile 中触发可折叠

Trigger the collapsible in JQUERY Mobile with a seperate button

我在 JQUERY 手机中有一个可折叠的,我正在使用它作为阅读更多。当可折叠项展开时,有一个固定按钮,屏幕底部显示关闭以关闭可折叠项。

我想要做的是使用屏幕底部的固定关闭按钮触发可折叠的关闭。我尝试过绑定方法,但我的经验不足阻碍了我的理解。

这是我使用的代码。

<div id="showbutton" data-role="collapsible" data-theme="b" data-transition="turn" data-content-theme="d" class="ui-shadow ui-btn-inline">
    <h2>Read more</h2>
    <h2 id="content">Lots and lots of content here</h2>

        <footer align="center" id="closefooter" data-role="footer" data-position="fixed" data-theme="b">
            <script>
                $(function() {
                    $("#closebutton").click(function() {
                        console.log("ok");
                    $( "#showbutton" ).trigger( "closebutton" );
                    });
                 });
            </script> 
        <a id="closebutton">close</a>
    </footer>

</div>

您可以按照此处所述使用 collapse() 方法:https://api.jquerymobile.com/collapsible/

$( ".selector" ).collapsible( "collapse" );

工作示例:http://jsfiddle.net/nmxav27t/

$(document).on("click", "#closebutton", function(event) {
    $("#showbutton").collapsible("collapse");
});

您需要在要用于关闭的按钮上绑定点击(或点击事件),然后在 showbutton id 上触发折叠。