1

我在Visual Studio中使用PhoneGap初学者模板设置了一个全新的项目。该模板按预期工作,但如果我尝试将jquery移动添加到页面中,并从中调用一个函数,则会报告jQuery未定义。PhoneGap&Visual Studio不复制脚本文件

这里是我的模板的javascript:

<script type="text/javascript" charset="utf-8" src="cordova-1.5.0.js"></script> 
    <script type="text/javascript" src="jquery.mobile.min.js"></script> 
    <script type="text/javascript"> 

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

    // once the device ready event fires, you can safely do your thing! -jm 
    function onDeviceReady() 
    { 
     document.getElementById("welcomeMsg").innerHTML += "Cordova is ready! version=" + window.device.cordova; 
     console.log("onDeviceReady. You should see this message in Visual Studio's output window."); 
     jQuery("#welcomeMsg").html("blah"); 
    } 

    </script> 

我CordovaSourceDictionary.xml看起来是也没关系:

<?xml version="1.0" encoding="utf-8"?> 
<!-- This file is auto-generated, do not edit! -jm --> 
<CordovaSourceDictionary> 
    <FilePath Value="www\cordova-1.5.0.js"/> 
    <FilePath Value="www\index.html"/> 
    <FilePath Value="www\jquery.mobile.min.js"/> 
    <FilePath Value="www\master.css"/> 
</CordovaSourceDictionary> 

但在尝试调试的WP7应用程序,我得到这些错误:

ScriptNotify :: Error:"'jQuery' is undefined" 
Log:"Error in success callback: Connection1 = 'jQuery' is undefined" 

回答

1

在您发布的代码中,您不包括jQuery核心... jQuery Mobile已建在jQuery Core之上,所以在jQuery Mobile或jQuery Mobile无法运行之前必须包含核心。在jQuery Mobile的下载页面上

通知的订单包括(mobile.css,那么核心JS,那么移动JS):

<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.css" /> 
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script> 
<script src="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.js"></script> 

来源:http://jquerymobile.com/download/

+0

谢谢!通过这个小事实吹倒。 – 2012-03-29 20:11:35