如何创建 jQuery Mobile 弹出提示机制?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9245867/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 10:32:42  来源:igfitidea点击:

How to create a jQuery Mobile Popup Alert mechanism?

jqueryhtmljquery-uijquery-mobile

提问by jini

I have been trying for hours to implement this and I am close but not there.

我已经尝试了几个小时来实现这一点,我很接近但不在那里。

The goal is simple. To have a functional popup alert that can be used from everywhere within an app.

目标很简单。具有可在应用程序内的任何位置使用的功能性弹出警报。

For example I have some code where I want to show a popup after a simple if test:

例如,我有一些代码,我想在简单的 if 测试后显示一个弹出窗口:

if (message.type == "Error") { //lets show a popup !!!

    $.mobile.changePage( "alert.html", {
    type: "post", 
    data: "alert_title="+message.type+"&alert_message="+message.content,
    transition: "pop",
    role: "dialog",
    reloadPage:true
});

As you can see I am passing in some custom data.

如您所见,我传入了一些自定义数据。

Here is the code for my alert page:

这是我的警报页面的代码:

<!DOCTYPE html>
<html>

    <head>
        <title>Alert</title>
        <!--#include virtual="header.inc" -->

    <script>
    alert("test");
    $('#alert_dialog').live('pageinit', function (event) {
    $("#alert_title").text($.urlParam('alert_title'));
    $("#alert_body").text($.urlParam('alert_message'));
    });
    </script>

    </head>

    <body>
        <div data-role="page" id="alert_dialog">
        <div data-role="header">
            <h1>Alert</h1>

        </div>

        <div data-role="content">
            <h1 id="alert_title">alert title</h1>
            <p id="alert_body">alert body</p>
            <a href="#" data-role="button" data-rel="back">OK</a>        
        </div>
    </div>
    </body>

</html>

The problem I am running is that no javascript is getting executed on alerts.htmlpage since it is injected to the DOM. Why would jQuery Mobile even allow us to send POST data using $.mobile.changePagewhen we cannot possibly use it?

我正在运行的问题是页面上没有执行 javascript,alerts.html因为它被注入到 DOM 中。$.mobile.changePage当我们不可能使用它时,为什么 jQuery Mobile 甚至允许我们发送 POST 数据 ?

Any help or suggestions?

任何帮助或建议?

回答by Kamran

Use this, it is JQM based popup like the Toast message on android.

使用它,它是基于 JQM 的弹出窗口,如 android 上的 Toast 消息。

https://gist.github.com/3136584

https://gist.github.com/3136584

回答by Phill Pafford

UPDATE:

更新:

Looks like this should be in 1.2 release:

看起来这应该在 1.2 版本中:

I know this really doesn't answer your question but the jQM Team thinks this should be ready for version 1.2 release:

我知道这真的不能回答你的问题,但 jQM 团队认为这应该准备好发布 1.2 版:

Posted on the jQM blog:

发表在 jQM 博客上: