2011-11-02 40 views
2

只是試圖讓jquery移動電話發射,但我無法讓我的你好世界射擊。Phonegap與jQuery的移動「你好世界」不工作

所有對Js的引用都是正確的。

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

    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no;" /> 

    <meta charset="utf-8"> 
    <link rel="stylesheet" href="style.css" type="text/css" media="screen" charset="utf-8"> 

     <script type="text/javascript" charset="utf-8" src="phonegap-1.1.0.js"></script> 
     <script type="text/javascript" charset="utf-8" src="jquery.js"></script> 
     <script type="text/javascript" charset="utf-8" src="jquery_mobile.js"></script> 


    <script type="text/javascript"> 
    document.addEventListener("deviceready", onDeviceReady, false); 


    function onDeviceReady() { 
     $(document).ready(function() { 
     $(document).bind("deviceready", function(){ 
      navigator.notification.alert("hello world"); 
     }); 
     }); 
    } 

    </script> 
    </head> 
    <body> 

    </body> 
</html> 

回答

1

試試這個:

<!DOCTYPE HTML> 
<html> 
    <head> 
    <meta name="viewport" content="width=320; user-scalable=no" /> 
    <meta http-equiv="Content-type" content="text/html; charset=utf-8"> 
    <title>Hello With JQuery Mobile</title> 
     <link rel="stylesheet" href="jquery.mobile/jquery.mobile-1.0rc1.min.css" type="text/css" charset="utf-8" /> 
     <script type="text/javascript" src="jquery.mobile/jquery-1.6.4.min.js"></script> 
     <script type="text/javascript" charset="utf-8" src="phonegap-1.1.0.js"></script> 
     <script type="text/javascript" src="jquery.mobile/jquery.mobile-1.0rc1.min.js"></script> 

    <script type="text/javascript"> 
     var onDeviceReady = function() { 
      alert("OnDeviceReady fired."); 
     }; 

     function init() { 
      document.addEventListener("deviceready", onDeviceReady, true); 
     } 
    </script> 

    </head> 
    <body onload="init();"> 

    </body> 
</html> 
+0

工作魅力,關心爲什麼要進入一個小細節? –

+0

太棒了!文檔尚未準備好添加事件偵聽器,直到正文加載。 –

+0

對不起,這是行不通的。我需要一些只會在jQuery,jquery mobile和document body加載後纔會觸發的東西。我測試瞭如果我刪除了jQuery手機腳本標籤會發生什麼情況,並且這仍然起作用。我還檢查了沒有觸發的'typeof(jQuery)',表明它不依賴於這些腳本,並且不會等待它們。 –

0

您是否在html和js ar位於Xcode中包含引用?

你應該嘗試通過在html正文中放置一些東西來開始調試,看看在你編譯和運行時是否出現這種情況。

+0

試過,HTML加載正常。 –

0

嘗試取出的addEventListener和功能是這樣的:

<script type="text/javascript"> 
    $(document).ready(function(){ 
     $(document).bind('deviceready', function(){ 
      navigator.notification.alert("hello world"); 
     }); 
    }); 
</script> 

沒有必要聽「deviceready」兩次。該文件將首先準備就緒,隨後JQM啓動設備準備就緒。

我希望它有幫助!

+0

不幸的是,沒有快樂 –

+1

@MildFuzz你有沒有嘗試在調用中放置其他函數來查看它們是否被觸發? – dSquared

0

我有一個類似的問題。註釋掉jquery或jquerymobile引用導致應用程序工作,但我無法讓它在標題中同時使用。這兩個文件都在phonegap的www文件夾中。我什至嘗試引用jquery.com的代碼,但它沒有奏效。