gpt4 book ai didi

javascript - jQuery Mobile 弹出窗口未在 .popup ('open' 上打开)

转载 作者:数据小太阳 更新时间:2023-10-29 05:58:18 24 4
gpt4 key购买 nike

我正在尝试使用 jQuery Mobile 1.3.1 的弹出窗口在登录凭据为假时警告用户。我从 jquerymobile 文档中的基本模板开始,但我无法使其与 $('#popupBasic').popup('open'); 一起使用如果我这样使用它;

     <div data-role="page">


<div data-role="header" data-tap-toggle="false">
</div><!-- /header -->

<div data-role="content">

<a href="#popupBasic" data-rel="popup">Tooltip</a>
<div data-role="popup" id="popupBasic">I will change this text dynamically if this popup works</div>


</div><!-- /content -->
</div><!-- /page -->

当我点击工具提示链接时,效果很好。但就我而言,没有任何点击,所以我正在尝试这样做;

                if(retVal){
$.mobile.changePage('index');
}
else{
$('#popupBasic').popup();
$('#popupBasic').popup("open");
}

这是在我的 ajax 登录函数进行回调之后,所以如果没有任何错误则 retVal 为真,如果有错误则为假(此时我试图显示弹出窗口)。顺便说一句,我所有的 js 部分都在

 $(document).on('pageinit', function(){});

所以我等到 jquerymobile 准备好页面。

当我这样做时会发生什么是在桌面浏览器上链接更改为

http://localhost/login#&ui-state=dialog

但不显示弹出窗口。经过一些刷新和缓存后,它开始显示。在 iOS 上也会发生同样的事情,但在 Android 上有时它会更改链接,但有时不会。

如果有人能帮我解决这个问题,我会很高兴。提前致谢。

最佳答案

那是因为当 pageinit 被触发时,弹出窗口还没有准备好进行操作。您需要使用 pageshow 来打开弹出窗口。这是你要做的:

  • pageinit 中进行ajax 调用。将数据存储在页面的 data 属性中。
  • 然后,在 pageshow 事件中,从数据中获取 if 并按照您想要的方式对其进行操作,然后打开弹出窗口。

代码如下:

$(document).on({
"pageinit": function () {
alert("pageinit");
//$("#popupBasic").popup('open'); will throw error here because the page is not ready yet
//simulate ajax call here
//data recieved from ajax - might be an array, anything
var a = Math.random();
//use this to transfer data betwene events
$(this).data("fromAjax", a);
},
//open popup here
"pageshow": function () {
alert("pageshow");
//using stored data in popup
$("#popupBasic p").html("Random : " + $(this).data("fromAjax"));
//open popup
$("#popupBasic").popup('open');
}
}, "#page1");

这是一个演示:http://jsfiddle.net/hungerpain/MvwBU/

关于javascript - jQuery Mobile 弹出窗口未在 .popup ('open' 上打开),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17559883/

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