1

我正在尝试使用 phonegap,但由于某种原因,我的 javascript 没有运行。到目前为止我尝试过的是:

<html>
<head>
    <meta charset="utf-8" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
    <link rel="stylesheet" type="text/css" href="css/index.css" />
    <title>Hello World</title>

    <script type="text/javascript" src="phonegap.js"></script>
    <script type="text/javascript" charset="utf-8">
        document.addEventListner("deviceready", onDeviceReady, false);

        function onDeviceReady() {
            alert('hey');
            document.addEventListener("online", onOnline, false);
            document.addEventListener("offline", onOffline, false);
        }

        function onOnline() {
            alert('device is online');
        }

        function onOffline() {
            alert('device is offline');
        }
    </script>
</head>
<body>
    <div class="app">
        <h1>PhoneGap</h1>
        <div id="deviceready" class="blink">
            <p class="event listening">Connecting to Device</p>
            <p class="event received">Device is Ready</p>
        </div>
    </div>
</body>

但由于某种原因,我没有收到警报。我在 IOS 7 上使用 phonegap 2.9.0

我也尝试过的是:

<html>
<head>
    <meta charset="utf-8" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
    <link rel="stylesheet" type="text/css" href="css/index.css" />
    <title>Hello World</title>

    <script type="text/javascript" src="phonegap.js"></script>
    <script type="text/javascript" charset="utf-8">
        document.addEventListener("deviceready", onDeviceReady, false);

// PhoneGap is ready
//
function onDeviceReady() {
    // Empty
}

// alert dialog dismissed
function alertDismissed() {
    // do something
}

// Show a custom alert
//
function showAlert() {
    navigator.notification.alert(
        'You are the winner!',  // message
        alertDismissed,         // callback
        'Game Over',            // title
        'Done'                  // buttonName
    );
}
    </script>
</head>
<body>
    <div class="app">
        <h1>PhoneGap</h1>
        <div id="deviceready" class="blink">
            <p class="event listening">Connecting to Device</p>
            <p class="event received">Device is Ready</p>
            <p><a href="#" onclick="showAlert(); return false;">Show Alert</a></p>
        </div>
    </div>
</body>

4

2 回答 2

2
        document.addEventListener("online", onOnline, false);
        document.addEventListener("offline", onOffline, false);

这些功能将仅用于建立新的互联网连接和禁用网络连接

打开应用程序时它不起作用。这些事件监听器“在线”和“离线”主要用于跟踪互联网连接是否可用。

此外,您不应使用 ios 7 中可能不支持的警报功能。在 phonegap 中使用通知类进行警报

于 2013-10-11T11:56:31.010 回答
0

试试这个它在我最后的工作,可能是你忘了添加cordova.js

<html>
<head>
    <meta charset="utf-8" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
    <link rel="stylesheet" type="text/css" href="css/index.css" />
       <script type="text/javascript" src="cordova.js"></script>
    <title>Hello World</title>
    <script type="text/javascript" src="phonegap.js"></script>
    <script type="text/javascript" charset="utf-8">
        document.addEventListener("deviceready", onDeviceReady, false);

        // PhoneGap is ready
        function onDeviceReady() {
            // Empty
        }

    // alert dialog dismissed
    function alertDismissed() {
        // do something
    }

    // Show a custom alert
     function showAlert() {
        navigator.notification.alert(
                                     'You are the winner!',  // message
                                     alertDismissed,         // callback
                                     'Game Over',            // title
                                     'Done'                  // buttonName
                                     );
    }
    </script>
</head>
<body>
    <div class="app">
        <h1>PhoneGap</h1>
        <div id="deviceready" class="blink">
            <p class="event listening">Connecting to Device</p>
            <p class="event received">Device is Ready</p>
            <p><a href="#" onclick="showAlert();">Show Alert</a></p>
        </div>
    </div>
</body>

于 2014-01-17T04:15:00.183 回答