2013-09-30 48 views
0

我正在嘗試獲取phonegap 3.0來加載jquery並沒有發生任何事情。Jquery無法在Phonegap 3.0上工作

例如這個工程:

<!DOCTYPE html> 
<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> 
    </head> 
    <body> 
     <div class="app"> 
      <input type="button" value="click me" id="myButton" onclick="alert('hello')" /> 
     </div> 
     <script type="text/javascript" src="cordova.js"></script> 
     <script type="text/javascript" src="js/index.js"></script> 
     <script type="text/javascript"> 
      app.initialize(); 
     </script> 
    </body> 
</html> 

但這並不:

<!DOCTYPE html> 
<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> 
    </head> 
    <body> 
     <div class="app"> 
      <input type="button" value="click me" id="myButton" /> 
     </div> 
     <script type="text/javascript" src="cordova.js"></script> 
     <script type="text/javascript" src="js/index.js"></script> 
     <script type="text/javascript" src="js/jquery.js"></script> 
     <script type="text/javascript"> 
      app.initialize(); 

      $(document).ready(function(){ 
       $('#myButton').click(function(){ 
        alert('hello'); 
       }); 
      }); 
     </script> 
    </body> 
</html> 

我不能爲我的生活想出解決辦法。我有正確的目錄中的jQuery

+0

定義「不起作用」。 – melancia

+0

請參閱控制檯並告訴我們您可以在那裏看到(f12 if chrome,ie) – Misters

回答

2

你的jQuery代碼需要運行在onDeviceReady(在index.js中找到)而不是document.ready。

0

我不確定具體是什麼問題,但我更新了Xcode,現在一切正常。此外,在更新Xcode之前,簡單地將它放入onDeviceReady仍然不起作用。