2012-07-18 63 views
4

我花了5個小時試圖使用jQuery Mobile顯示加載消息。相反,我得到:當試圖用jQuery Mobile調用'loading'時未捕獲TypeError

Uncaught TypeError: Object #<Object> has no method 'loading'

這裏是我的代碼:

<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> 

回答

2

您遇到的例外是由於不正確方法參考,如錯誤中所述:

Uncaught TypeError: Object # has no method 'loading'

在1.2中添加了loading()方法,但您使用的是1.1.1,這就是爲什麼它聲明它沒有loading方法。

Show or hide the page loading message, which is configurable via $.mobile.loader prototype options as described in the widget docs or can be controlled via a params object.

用法:

//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); 
+0

我在哪裏可以找到1.2版本? – user1271775 2012-07-18 02:15:37

+0

看起來好像他們還沒有發佈1.2版本。 http://jquerymobile.com/blog/2012/01/10/upcoming-releases-1-0-1-1-1-and-beyond/ – RobB 2012-07-18 02:18:58

+0

所以我可以做一個簡單的工作與$ .mobile罰款。 showPageLoadingMsg()請?因爲我把它和沒有加載味精出現,沒有錯誤apper。 – user1271775 2012-07-18 02:22:22

-1

最後我找到了解決辦法

它不能直接從一個簡單的JavaScript函數調用,我需要用一個頁面

$("#Step1").live("pageshow", function() { 
    $.mobile.showPageLoadingMsg(); 
}); 
0

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

$.mobile.loading("show"); 

並且該方法是在移動的jQuery 1.2.0。

它支持

$.mobile.showPageLoadingMsg(); 

而且你可以在mobileinit方法配置loadMessage。

EX:

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

我有同樣的問題,終於讓我找到它。