简体   繁体   English

所有页面的jQuery移动全局弹出窗口

[英]jQuery mobile global popup for all pages

How can I have global(common) popup for all pages in one html file??? 如何在一个html文件中为所有页面提供全局(通用)弹出窗口???
I try this one. 我试试这个。 but not working... 但没有工作......

<div data-role="page" id="home"></div>
<div data-role="page" id="news"></div>
<div data-role="page" id="details"></div>
<div data-role="popup" id="settings" data-corners="false" data-theme="none" data-shadow="false" data-tolerance="0,0"></div>

If you're using jQuery Mobile 1.4.1 如果你正在使用jQuery Mobile 1.4.1

Documentation says that you can reuse the same popup on multiple pages if you declare it as a direct child of the body element. 文档说如果您将其声明为body元素的直接子元素,则可以在多个页面上重复使用相同的弹出窗口。 It can then appear on any page in the document: 然后它可以出现在文档的任何页面上:

<div id="popup-outside-page" data-theme="a">
    <!-- This popup has its theme explicitly defined via data-theme="a"
         because it has no parent from which to automatically inherit
         its theme -->
    <ul data-role="listview">
        <li>Global Menu</li>
        <li><a href="#demo-intro">Intro Page</a></li>
        <li><a href="#other-page">Other Page</a></li>
        <li><a href="#third-page">Third Page</a></li>
    </ul>
</div>
<div id="other-page" data-role="page" data-url="other-page">
    <div data-role="header">
        <a href="#popup-outside-page" data-rel="popup">Menu</a>
        <h1>Another Page</h1>
    </div>
    <div role="main" class="ui-content">
        <p>This is another page that can be reached using the links in the global menu.</p>
    </div>
</div>
<div id="third-page" data-role="page" data-url="third-page">
    <div data-role="header">
        <a href="#popup-outside-page" data-rel="popup">Menu</a>
        <h1>Third Page</h1>
    </div>
    <div role="main" class="ui-content">
        <p>This is a third page that can be reached using the links in the global menu.</p>
    </div>
</div>

If you define the popup outside of any page, then you must take care to instantiate the popup widget yourself. 如果在任何页面之外定义弹出窗口,则必须注意自己实例化弹出窗口小部件。 You can do this as early as DOMReady, because the popup is not on any page: 您可以早在DOMReady中执行此操作,因为弹出窗口不在任何页面上:

// Instantiate the popup on DOMReady, and enhance its contents
$( function() {
    $( "#popup-outside-page" ).enhanceWithin().popup();
});

If you wish the popup to be opened from a set of links, then you must also handle that manually, because automatic handling via data-rel="popup" is restricted to popups on the active page. 如果您希望从一组链接打开弹出窗口,那么您还必须手动处理,因为通过data-rel =“popup”的自动处理仅限于活动页面上的弹出窗口。

If you're using older versions of jQuery Mobile 如果您使用的是旧版本的jQuery Mobile

Short answer is that you can't. 简短的回答是,你做不到。 The documentation states that: 文件指出:

A popup div has to be nested inside the same page as the link 弹出div必须嵌套在与链接相同的页面内

So you'd have to copy and paste the popup to every page you want it to appear, which doesn't sound like a good solution. 因此,您必须将弹出窗口复制并粘贴到您希望它出现的每个页面,这听起来不是一个好的解决方案。

When I need something that behaves like a global popup I usually go with a dialog , which can be opened from any page. 当我需要一些行为像全局弹出窗口的东西时,我通常会使用一个对话框 ,可以从任何页面打开。

The dialog itself has the same structure as a page: 对话框本身具有与页面相同的结构:

<div id="diag" data-role="dialog">
    <div data-role="header" data-theme="d">
        <h1>Info</h1>
    </div>
    <div data-role="content" data-theme="c">
        <h1>Thank you for your time!</h1>
        <a data-role="button" data-rel="back">Ok</a>
    </div>
</div>

And you can open it programatically: 你可以以编程方式打开它:

$.mobile.changePage("#diag");

Or with the click of a button as any other jQuery mobile page: 或者点击按钮作为任何其他jQuery移动页面:

<a href="#diag" data-role="button" data-rel="dialog" data-theme="a">Open dialog</a>

Take a look at this response 看看这个回复

https://stackoverflow.com/a/12092465/591254 https://stackoverflow.com/a/12092465/591254

There is a plugin that could help you while the jquery mobile team add support for popups defined outside the page they are used in. Notice the live demo does not work, but in local and replacing the jquery js it works. 有一个插件可以帮助你,而jquery移动团队添加对他们使用的页面外定义的弹出窗口的支持。请注意,现场演示不起作用,但在本地并替换它工作的jquery js。

This is the jqm request: 这是jqm请求:

https://github.com/jquery/jquery-mobile/issues/4565 https://github.com/jquery/jquery-mobile/issues/4565

Apparently it could be added within jqm 1.4 显然它可以在jqm 1.4内添加

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM