2014-03-29 41 views
0

我一直在試圖做一個觸摸事件的警報框,但我不工作。我已經上傳到Phonegap版本並將其安裝在手機中,但它無法識別touchstart事件。爲什麼觸摸事件不起作用?

這是代碼:

的index.html

<!DOCTYPE html> 
<html> 
    <head> 
     <meta charset="utf-8" /> 
     <meta name="format-detection" content="telephone=no" /> 
     <!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 --> 
     <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> 

    </head> 
    <body> 
     <div id="box"></div> 

     <div id="box2"></div> 

     <div id="box3"></div> 



     <script type="text/javascript" src="cordova.js"></script> 
     <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> 

     <script type="text/javascript" src="js/index.js"></script> 
     <script> 
       $(document).one('deviceready', App.initialize()); 
     </script> 
    </body> 
</html> 

index.css

#box { 
    width: 300px; 
    height: 300px; 
    background-color: yellow; 
} 
#box2 { 
    width: 300px; 
    height: 300px; 
    background-color: red; 
} 

#box3 { 
    width: 300px; 
    height: 300px; 
    background-color: blue; 
} 

index.js

var App = { 
    initialize: function() { 
     alert("App initialized"); 
     this.clickEvents(); 
    }, 
    clickEvents: function() { 
     $("#box").on('touchstart',function() { 
      alert("Yellow box jQuery and touchstart event"); 
     }); 
     $("#box2").on('touchstart',function(){ 
      alert("Red box jQuery and touchstart event"); 
     }); 
     $("#box3").on('touchstart', function(){ 
      alert("Blue box jQuery and touchstart event"); 
     }); 
    } 
    } 
+0

讓我知道,如果是它的工作 –

+0

弄來警報( 「應用程序初始化」)? – manukv

回答

0

變化

$(document).one('deviceready', App.initialize()); 

$(document).on('deviceready', App.initialize()); 
+0

我已經改變了方法,但它也不工作 – user3062745

0

可能爲時已晚,但... 你應該交給App.initialize作爲一個回調參數:

$(document).on('deviceready', App.initialize);