gpt4 book ai didi

javascript - JQuery Mobile 菜单静态页面更改

转载 作者:行者123 更新时间:2023-12-03 12:21:05 26 4
gpt4 key购买 nike

我正在尝试修复页面更改时的顶部菜单。示例:

<div data-role="page" id="page1">
//page 1 contents
</div>
<div data-role="page" id="page2">
//page 2 contents
</div>

和我的顶部菜单

<div id="top-menu">
</div>

有什么办法可以让菜单代码不再出现在每一页上吗?我希望我的菜单 div 集中在所有页面上。

有什么想法吗?

谢谢,安德里亚

最佳答案

不,“页面”的概念不允许在它们之间共享静态内容。

但我至少看到两个解决方案:

  • 仅使用包含菜单的一页,以及许多隐藏菜单 div封装您的内容(例如 <div data-role="content" id="page1" class="hidden"> )。使用菜单导航,您只需显示/隐藏您需要的内容

  • 使用一些 JavaScript 技巧:

    $(document).on("pagebeforeshow", "[id^=page]", function(event)
    {
    // "move" the menu to the content of the current page
    // (you have to add IDs to each page like 'page1content')
    $("#top-menu").prependTo("#" + this.id + "content");
    });

关于javascript - JQuery Mobile 菜单静态页面更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24449941/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com