2012-04-15 58 views
0

我有以下代碼在我實現jQuery Mobile之前工作正常。現在,我沒有收到任何測試警報,所以它讓我想到它沒有執行onbodyload功能。我如何得到這個工作?如何在手機上運行加載功能/ jquery mobile iOS應用程序

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

    <meta http-equiv="Content-type" content="text/html; charset=utf-8"> 
    <link rel="stylesheet" href="style.css" type="text/css" />  

    <!-- iPad/iPhone specific css below, add after your main css > 
    <link rel="stylesheet" media="only screen and (max-device-width: 1024px)" href="ipad.css" type="text/css" />   
    <link rel="stylesheet" media="only screen and (max-device-width: 480px)" href="iphone.css" type="text/css" />  
    --> 
    <!-- If your application is targeting iOS BEFORE 4.0 you MUST put json2.js from http://www.JSON.org/json2.js into your www directory and include it here --> 
    <script type="text/javascript" charset="utf-8" src="cordova-1.5.0.js"></script> 
    <script type="text/javascript" charset="utf-8" src="functions.js"></script> 

    <script type="text/javascript" charset="utf-8" src="articles.js"></script> 
    <link rel="stylesheet" type="text/css" href="jquery/jquery.mobile-1.1.0.min.css" /> 

     <script type="text/javascript" src="jquery/jquery-1.7.1.min.js"></script> 

     <!-- <script type="text/javascript" src="main.js"></script> --> 

     <script type="text/javascript" src="jquery/jquery.mobile-1.1.0.js"></script> 

    <script type="text/javascript" charset="utf-8"> 


    function onBodyLoad() 
    {  
     document.addEventListener("deviceready",onDeviceReady,false); 
     alert('body'); 
    } 

    /* When this function is called, PhoneGap has been initialized and is ready to roll */ 
    /* If you are supporting your own protocol, the var invokeString will contain any arguments to the app launch. 
    see http://iosdevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html 
    for more details -jm */ 
    function onDeviceReady() 
    { 
    alert('device'); 

     // do your thing! 
     parms = getUrlVars(); 
     type = parms['type']; 
     page = parms['page']; 
     if(page=='') { 
     page = 0; 
     } 
     filter_value = parms['filter_val']; 


     vars = articles_get_info(type,page,filter_value); 

     document.getElementById('pagetitle').innerHTML = vars['title']; 
     document.getElementById('pagecontent').innerHTML = vars['page']; 

    } 

    </script> 
    </head> 
    <body onload="alert('hello');onBodyLoad()"> 
    <div data-role="page"> 
    <div data-role="header" id="header"><a href="index.html" style="float:right;" class="btn">Back</a> 
     <h1 id="pagetitle"></h1> 
     </div> 
     <div data-role="content" id="pagecontent"> 

     </div> 
     </div> 
    </body> 
</html> 

我試着更換onbodyload(),並刪除的onload =「」這下面的,但它仍然沒有奏效:

window.addEventListener('load', function() { 
    document.addEventListener('deviceready', onDeviceReady, false); 
}, false); 
+0

i'f只是有一個簡單的方法來獲得在Xcode的js錯誤。 – David 2012-04-15 13:53:42

+0

您可以在Chrome或Safari的開發人員工具中獲得JS錯誤。爲什麼不使用'$(document).ready()'快捷鍵? – 2012-04-15 14:17:20

回答

0

PhoneGap documentatio N,你可以這樣做:

$(function() { 
    document.addEventListener("deviceready", onDeviceReady, false); 
}); 

功能onDeviceReady(){...}

0

上使用jQuery的速記符號的文件負載:

$(function(){ 
    //The document is loaded. Put your code here 

});

相關問題