简体   繁体   English

启动时仅显示一次jQuery移动对话框(Web应用程序)

[英]Show jquery mobile dialog only once on startup (web app)

My problem is that following code works fine (dialog show once on startup), but when I navigate to another page (with standard ajax activated), and then navigate back to the first page, the dialog is showing again (and then in a loop manner when I click "dismiss"). 我的问题是以下代码可以正常工作(启动时会显示一次对话框),但是当我导航到另一页(激活了标准ajax),然后又导航回到第一页时,对话框再次显示(然后循环显示)当我点击“关闭”时

What am I doing wrong? 我究竟做错了什么?

Code looks like that: 代码如下所示:

$(document).on('pageinit', '#pageindex', function(event) {
        setTimeout(function(){
            $('#dialog').click();
            $('#dialog').remove();
        },1000);
});

For a quick fix, replace .on with .one . 要快速修复, .on.one替换.on However, normally pageinit event should fire once only, so there must be something causing it to fire multiple times. 但是,通常pageinit事件应该只触发一次,因此必须有某种原因导致它多次触发。

The following code is executed once on single/multipage page and multiple pages approach: 以下代码在单页/多页页面上执行一次,并且多页方法:

$(document).on('pageinit', '#pageindex', function (event) {
    $(this).off(event);
    setTimeout(function () {
        $('#dialog').click();
        $('#dialog').remove();
    }, 1000);
});

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

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