【问题标题】:Trigger the collapsible in JQUERY Mobile with a seperate button使用单独的按钮在 JQUERY Mobile 中触发可折叠
【发布时间】:2019-07-25 05:59:18
【问题描述】:

我在 JQUERY Mobile 中有一个可折叠的文件,我将其用作阅读更多内容。当折叠器展开时,有一个固定按钮,屏幕底部会显示关闭,这样您就不必滚动回顶部来关闭折叠器。

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

这是我正在使用的代码。

<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>

【问题讨论】:

    标签: javascript jquery html jquery-mobile


    【解决方案1】:

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

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

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

    【讨论】:

      【解决方案2】:

      您可以使用如下所述的 collapse() 方法:https://api.jquerymobile.com/collapsible/

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

      【讨论】:

      • 我已经尝试过了,但问题主要是我对它的工作原理缺乏了解。请你给我一个例子。我使用 (#showbutton) 作为选择器,但我无法让它触发可折叠。是容器问题还是语法问题?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-12-30
      • 1970-01-01
      • 2019-10-15
      • 1970-01-01
      • 2017-03-15
      • 2012-01-14
      • 2012-11-18
      相关资源
      最近更新 更多