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>

我从 https://github.com/jreid01/jqm-api
下载了此示例(示例-3)这是O'Reilly Webcast: The jQuery Mobile API In-Depth http://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?我在这里错过了什么概念?

谢谢!

这很简单。"方向"事件不会在文档对象上触发,而是在窗口对象上触发。您下载的示例中似乎存在错误。

最新更新