4

我花了 5 个小时尝试使用 jQuery Mobile 显示加载消息。相反,我得到:

未捕获的类型错误:对象 #<Object> 没有方法“加载”

这是我的代码:

<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.js"></script>

<script type="text/javascript">
    $.mobile.loading("show");
</script>

这是当前代码:

    <head> 
    <title>My Page</title> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.css" />
    <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>

    <script src="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.js"></script>

    <script type="text/javascript">
        $.mobile.showPageLoadingMsg();
    </script>
</head> 
4

3 回答 3

2

您遇到的异常是由于方法引用不准确,如错误中所述:

未捕获的类型错误:对象 # 没有“加载”方法

loading()方法是在 1.2 中添加的,但您使用的是 1.1.1,这就是它声明它没有loading方法的原因。

显示或隐藏页面加载消息,可通过小部件文档中描述的 $.mobile.loader 原型选项进行配置,也可以通过 params 对象进行控制。

用法:

//cue the page loader
$.mobile.loading( 'show' );

//use theme swatch "b", a custom message, and no spinner
$.mobile.loading( 'show', { theme: "b", text: "foo", textonly: true });

您应该为您的版本使用的方法是showPageLoadingMsg().

用法:

//cue the page loader
$.mobile.loadingMessage = 'Loading...Please wait';
$.mobile.showPageLoadingMsg();

//use theme swatch "b", a custom message, and no spinner
$.mobile.showPageLoadingMsg("b", "This is only a test", true);
于 2012-07-18T02:12:12.463 回答
0

您使用 jquery.mobile-1.1.1.min.js 。不支持 jQuery 移动 1.1.1

$.mobile.loading("show");

这个方法在 jQuery mobile 1.2.0 中。

支持

$.mobile.showPageLoadingMsg();

您可以在mobileinit方法中配置 loadMessage 。

前任:

 $.mobile.loadingMessage = "Loading Message"; 
 $.mobile.loadingMessageTextVisible = true;
 $.mobile.loadingMessageTheme="a";

我有同样的问题,最后我找到了。

于 2012-07-24T08:49:01.473 回答
-1

最后我找到了解决方案

它不能直接从简单的 javascript 函数中调用,我需要将它与页面一起使用

$("#Step1").live("pageshow", function () {
    $.mobile.showPageLoadingMsg();  
});
于 2012-07-18T02:26:23.097 回答