PhoneGap Javascript除在索引文件中以外不起作用 [英] PhoneGap Javascript not working other than in index file

查看:69
本文介绍了PhoneGap Javascript除在索引文件中以外不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在尝试运行javascript函数(要测试的警报),但是在除index.html以外的页面中却没有触发.

Hi I'm trying to run a javascript function (an alert to test) but it is not firing when in a page other than the index.html.

这是一个不触发javascript警报的页面示例(请注意,<已从所有标记中删除,以便在堆栈溢出中呈现):

here is an example of a page that is not firing the javascript alert ( note that < is removed from all of the tags so as to render in stack overflow):

<!DOCTYPE html>
<html>
    <head>
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no;" />
        <meta http-equiv="Content-type" content="text/html; charset=utf-8">
        <script type="text/javascript" charset="utf-8" src="phonegap-1.0.0.js"></script>
        <script type="text/javascript" charset="utf-8">
            document.addEventListener("deviceready", onDeviceReady, false);

            // PhoneGap is loaded and it is now safe to make calls PhoneGap methods
            //
            function onDeviceReady() {
            document.addEventListener("deviceready", onDeviceReady, false);
            }


            function onDeviceReady() {
            alert("test");
            navigator.notification.alert("PhoneGap is working");
            }

        </script>

        <link rel="stylesheet"  href="http://code.jquery.com/mobile/1.0rc1/jquery.mobile-1.0rc1.min.css" />
        <link rel="stylesheet" href="docs/_assets/css/jqm-docs.css" />
        <script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
        <script src="experiments/themeswitcher/jquery.mobile.themeswitcher.js"></script>
        <script src="docs/_assets/js/jqm-docs.js"></script>
        <script src="http://code.jquery.com/mobile/1.0rc1/jquery.mobile-1.0rc1.min.js"></script>
        <link rel="stylesheet" href="n_style.css" />

    </head>
    <body onload="onBodyLoad()">


    </body>
</html>

推荐答案

onDeviceReady仅在应用程序启动时触发一次.请参阅文档: http://docs.phonegap.com/en/1.0.0/phonegap_events_events.md.html#deviceready

onDeviceReady only fires once when the app starts up. See documentation: http://docs.phonegap.com/en/1.0.0/phonegap_events_events.md.html#deviceready

该功能指示PhoneGap已完全加载.

It's the function that indicates PhoneGap is fully loaded.

这篇关于PhoneGap Javascript除在索引文件中以外不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆