我可以在Cordova 2.5上多次收听设备吗?

Ngu*_*inh 4 javascript cordova

我可以为每个html页面注册'deviceready'事件吗?我使用Cordova 2.5的初始化代码,它工作正常.当我将这些代码复制到一个新的html文件时,它总是调用index.html的initialize()函数.

var app = {
    // Application Constructor
    initialize: function() {
        this.bindEvents();
    },
    // Bind Event Listeners
    //
    // Bind any events that are required on startup. Common events are:
    // 'load', 'deviceready', 'offline', and 'online'.
    bindEvents: function() {
        document.addEventListener('deviceready', this.onDeviceReady, false);
    },
    // deviceready Event Handler
    //
    // The scope of 'this' is the event. In order to call the 'receivedEvent'
    // function, we must explicity call 'app.receivedEvent(...);'
    onDeviceReady: function() {
        app.receivedEvent('deviceready');
    },
    // Update DOM on a Received Event
    receivedEvent: function(id) {
        console.log('Received Event: XXX ' + id);

    }
};
Run Code Online (Sandbox Code Playgroud)

=============== HTML文件:

....

 <script type="text/javascript">
                app.initialize();
                </script>
Run Code Online (Sandbox Code Playgroud)

....

Nis*_*air 6

设备就绪只会触发一次.只有当应用程序被杀死并再次打开时,它才会下次触发.