2012-09-23 22 views
0

我有一個簡單的例子,做一些事情,當用戶改變移動設備的方向:文件與Android和PhoneGap的窗口對象 - jQuery Mobile的

<script> 
$(document).on("orientationchange", function(event) { 
if (event.orientation === "landscape") { 
    // We have changed to landscape orientation, so we have more room 
    // Make the headers and footers longer! 
    $("header h1").text("jQuery Mobile Demonstration Application") 
    $("footer h3").text("O'Reilly Multimedia Services") 
} else { 
    // Back in portrait orientation, so return header and footer to original length. 
    $("header h1").text("jQuery Mobile") 
    $("footer h3").text("O'Reilly") 
} 
}) 
</script> 

我下載這個例子(例子3)從https://github.com/jreid01/jqm-api
其是用於O'Reilly Webcast: The jQuery Mobile API In-Depthhttp://www.youtube.com/watch?v=I6Y4a0hA8tI
源代碼我裝載本實施例中與PhoneGap的:

public class MainActivity extends DroidGap { 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     super.loadUrl("file:///android_asset/www/example-3.html"); 
    } 
} 

現在,第是例子不適用於我的nexus-one,也不適用於android模擬器。在做了一些實驗後,當我將document更改爲window時,該示例確實有效。
是什麼原因document對象不起作用?我在這裏想念什麼概念?

謝謝!

+1

您是否在等待deviceready事件? –

+0

沒有..我唯一的腳本(除了jQuery \手機腳本)是我粘貼在帖子 –

+1

在這種情況下,你應該閱讀:http://docs.phonegap.com/en/2.1.0/ cordova_events_events.md.html#deviceready –

回答

1

這很簡單。 「方向」事件不會在文檔對象上觸發對象,而是在窗口對象上觸發。您下載的示例中似乎存在一個錯誤。