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

标签 javascript jquery html jquery-mobile

我在 JQUERY Mobile 中有一个可折叠的,我正在使用它作为阅读更多。当可折叠项展开时,有一个固定按钮,屏幕底部显示关闭以关闭可折叠项,因此您无需滚动回顶部即可关闭可折叠项。

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

这是我使用的代码。

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

最佳答案

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

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

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

关于javascript - 使用单独的按钮在 JQUERY Mobile 中触发可折叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54974500/

相关文章:

javascript - 使用 JQuery 淡出动画

javascript - webpack 目录中的多个条目

jquery - 在移动设备的右侧获取空白区域。表格和文本的某些部分超出了移动宽度

GWT 中的 Java 定时器

javascript - 使用两个按钮显示/隐藏 div

javascript location.hash 在 IE 中刷新

javascript - jQuery .each 首先附加第二个值等

javascript - 如何使用 jQuery 悬停、更改、切换图片

jquery - 如何使用 JQuery 调整窗口大小?

css - 绝对定位和CSS粘性页脚