【问题标题】:Updating a DIV inside a Collapsible in JQuery Mobile only when the Collapsible is opened (eg. load on demand)仅当 Collapsible 打开时(例如,按需加载)才在 JQuery Mobile 中更新 Collapsible 中的 DIV
【发布时间】:2015-06-18 06:52:05
【问题描述】:

我正在尝试执行对外部程序的调用,以在 JQuery Mobile 的可折叠项内的 DIV 中创建内容,以便在打开可折叠项时出现 JQM 可折叠项中的 div 时运行一些代码。我正在尝试使用 jquery.appear 插件 (https://github.com/morr/jquery.appear),如下所示:

<div id="coll2" data-role="collapsible" data-mini="true" data-inset="false" data-iconpos="right">
  <h1>Collapsible 1</h1>
  Collapsible Title! 
  <div id="2wrapper"></div>
</div>

<script type="text/javascript">

$(document.body).on('appear', '#2wrapper', function() {
  // this element is now inside browser viewport

    alert("Script running");
    $("#2wrapper").load('some-external-program-content.cgi');

});

</script>

我显然遗漏了一些东西,因为当可折叠打开时 div 没有更新。在这种情况下会出现工作吗?或者有没有更有效的方法来实现这种“按需”加载可折叠内容的方式?

【问题讨论】:

    标签: html jquery-mobile external jquery-mobile-collapsible


    【解决方案1】:

    您不需要任何插件,只需在可折叠设备上使用expand 事件即可:

    $(document).on("collapsibleexpand", "#coll2", function(event, ui)
    {
        $("#2wrapper").load('some-external-program-content.cgi');
    });
    

    ...顺便说一句:最好避免 ID 以数字开头(即使 HTML5 允许这样做)。

    【讨论】:

    • 谢谢!是的,我同时在stackoverflow.com/questions/8399882/… 找到了一个类似的答案,并改用了 expand 事件。也非常感谢您的回复。也感谢您对领先数字不理想的指导。干杯。
    猜你喜欢
    • 1970-01-01
    • 2014-01-20
    • 1970-01-01
    • 1970-01-01
    • 2017-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-13
    相关资源
    最近更新 更多