Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript PhoneGap显示加速计值_Javascript_Jquery_Html_Mobile_Cordova - Fatal编程技术网

Javascript PhoneGap显示加速计值

Javascript PhoneGap显示加速计值,javascript,jquery,html,mobile,cordova,Javascript,Jquery,Html,Mobile,Cordova,我使用phonegap来获取加速计的值并打印出来,但我不确定如何在主体中显示它。我也在使用JQuery。此代码取自Cordova PhoneGap网站上的加速计示例 <!DOCTYPE html> <html> <head> <title>Acceleration Example</title> <script type="text/javascript" charset="utf-8" src="cordo

我使用phonegap来获取加速计的值并打印出来,但我不确定如何在主体中显示它。我也在使用JQuery。此代码取自Cordova PhoneGap网站上的加速计示例

<!DOCTYPE html>
<html>
  <head>
    <title>Acceleration Example</title>

    <script type="text/javascript" charset="utf-8" src="cordova-1.7.0.js"></script>
    <script type="text/javascript" charset="utf-8">

    // Wait for Cordova to load
    //
    document.addEventListener("deviceready", onDeviceReady, false);

    // Cordova is ready
    //
    function onDeviceReady() {
        navigator.accelerometer.getCurrentAcceleration(onSuccess, onError);
    }

    // onSuccess: Get a snapshot of the current acceleration
    //
    function onSuccess(acceleration) {
        alert('Acceleration X: ' + acceleration.x + '\n' +
              'Acceleration Y: ' + acceleration.y + '\n' +
              'Acceleration Z: ' + acceleration.z + '\n' +
              'Timestamp: '      + acceleration.timestamp + '\n');
              document.writeln(
              'Acceleration X: ' + acceleration.x + '\n' +
              'Acceleration Y: ' + acceleration.y + '\n' +
              'Acceleration Z: ' + acceleration.z + '\n' +
              'Timestamp: '      + acceleration.timestamp + '\n');
    }

    // onError: Failed to get the acceleration
    //
    function onError() {
        alert('onError!');
    }

    </script>
  </head>
  <body>
    <h1>Example</h1>
    <p>getCurrentAcceleration</p>
  </body>
</html>

在HTML标记中,使用以下代码

<p id="ax"></p>
<p id="ay"></p>
<p id="az"></p>
或者像这样使用jQuery

$("ax").html(acceleration.x);
$("ay").html(acceleration.y);
$("az").html(acceleration.z);

好的,我加了这个,但是在我的Android设备上,它没有显示任何你现在遇到的问题??
$("ax").html(acceleration.x);
$("ay").html(acceleration.y);
$("az").html(acceleration.z);