2012-07-16 55 views
-1

的PhoneGap 1.8.1 - 2.2 Android的API - 的jQuery 1.7.1 - jQueryMobile 1.0的PhoneGap,机器人,后退按钮:不能使它工作

我做了一个非常简单的应用程序来测试这个我只是无法让它工作。这里是。

INDEX.HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
     "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
    <title>TestApp</title> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <link rel="stylesheet" href="jquery.mobile-1.1.0/jquery.mobile-1.1.0.min.css"/> 
    <script type="text/javascript" src="jquery.min.js"></script> 
    <script type="text/javascript" src="jquery.mobile-1.1.0/jquery.mobile-1.1.0.min.js"></script> 
    <script type="text/javascript"> 
     function onDeviceReady() { 

      document.addEventListener("backbutton", onBackButton); 
     } 

     function onBackButton(e){ 
      console.log("C'mon guv! Gimme a chance!"); 
     } 

     document.addEventListener("deviceready", onDeviceReady, false); 

    </script> 
    <script type="test/javascript" src='cordova-1.8.1.js'></script> 

</head> 

<body> 
<div id="homepage" data-role="page" data-theme="a"> 
    <div data-role="header"> 
     <h1>Work with me here</h1> 
    </div> 

    <div data-role="content"> 
     I am page 1. 
     <a href="#char-1" data-role="button">Next</a> 
    </div> 
</div> 

<div id="char-1" data-role="page" data-theme="a"> 
    <div data-role="content">HAHAHA!</div> 
</div> 


</body> 
</html> 

的AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
      package="com.example" 
      android:versionCode="1" 
      android:versionName="1.0"> 
    <uses-sdk android:minSdkVersion="2" android:targetSdkVersion="14"/> 
    <supports-screens 
     android:largeScreens="true" 
     android:normalScreens="true" 
     android:smallScreens="true" 
     android:resizeable="true" 
     android:anyDensity="true" /> 

    <application android:label="@string/app_name"> 
     <activity android:name="MyActivity" 
        android:label="@string/app_name"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN"/> 
       <category android:name="android.intent.category.LAUNCHER"/> 
      </intent-filter> 
     </activity> 
    </application> 
</manifest> 

增编 - 我认为问题是, 'deviceready' 事件或者不闪光或代码之前大火结合到事件。不知道如何解决它。

让我知道是否有更多的信息我需要提供..我很难过。

回答

1

我很惭愧地承认这一点。

<script type="test/javascript" src='cordova-1.8.1.js'></script> 

这不是测试/ JavaScript ...这是文本/ JavaScript。

:(

+0

也可能在时间轴上装得太迟。 – 2013-12-09 07:02:25

1

据我所知,后退按钮事件不在onDeviceReady内工作。您必须在每个页面展示中触发事件。就我而言,它是这样工作的,

function onDeviceReady(){ 
    /*Back event handler for all pages navigation*/ 
    $(document).bind ('pageshow', function (e, data) { 
     if ($.mobile.activePage.attr('id') == 'index') { 
      document.addEventListener("backbutton", function() { 
       setTimeout(function() {navigator.app.exitApp();}, 100); 
      }, true); 
     } 
     else{ 
      document.addEventListener("backbutton", function() { 
       setTimeout(function() {$.mobile.changePage("#index");}, 100); 
      }, true); 
     } 
    }); 


} 

在我的应用程序,当你从第一屏幕按后退按钮,它退出应用程序,如果你按下任意页面里面,它会自动来到第一页。

+0

我写了这个:https://gist.github.com/3129987和我没有得到它的工作:/ – Trevoke 2012-07-17 15:21:42

+0

老兄,你在你的代码错过的PhoneGap是JS不是?。 – Akilan 2012-07-18 04:47:53

+0

?它低于代码位 – Trevoke 2012-07-18 05:49:41