0

我发现以下代码在移动 Web 应用程序中显示 toast 样式的警报,我想用它来向移动客户端中的用户显示这些消息:

var toast = function (msg) {
$("<div class='ui-loader ui-overlay-shadow ui-body-e ui-corner-all'><h3>" + msg + "</h3></div>")
.css({
    display : "block",
    opacity : 0.90,
    position : "fixed",
    padding : "7px",
    text-align : "center",
    width : "270px",
    left : ($(window).width() - 284) / 2,
    top : $(window).height() / 2
})
.appendTo($.mobile.pageContainer).delay(1500)
.fadeOut(400, function () {
    $(this).remove();
});
}

我像这样从javascript调用它:

toast("This is a test message");

当我导航到此代码所在的页面时,它第一次显示该消息正常。当我返回页面时(第一次访问后),我收到此错误:

0x800a138f - JavaScript 运行时错误:无法获取未定义或空引用的属性“pageContainer”

是什么导致了这个错误,我该如何解决这个错误?无论页面访问多少次,我都希望该功能能够执行。

4

0 回答 0