2013-04-13 73 views
0

這裏是我的default.html和文件支持jQuery的

<!DOCTYPE html> 
<html> 
<head> 
<meta charset="utf-8" /> 
<title>app1</title> 

<!-- WinJS references --> 
<link href="//Microsoft.WinJS.1.0/css/ui-dark.css" rel="stylesheet" /> 
<script src="//Microsoft.WinJS.1.0/js/base.js"></script> 
<script src="//Microsoft.WinJS.1.0/js/ui.js"></script> 

<!-- app1 references --> 
<link href="/css/default.css" rel="stylesheet" /> 
<script src="/js/default.js"></script> 
<script src="/js/jquery.js"></script> 

</head> 
<body> 
<button id="buttonYouWantToClick">Button</button> 
<div id="result"></div> 

<p>Content goes here</p> 
</body> 
</html> 

和default.js文件。我在app.start()函數之前放jquery代碼。

... 
    $(document).ready(function() { 
     $('#buttonYouWantToClick').click(function() { 
      $('#result').html('jQuery works!'); 
     }); 
    }); 
    app.start(); 
})(); 

我也試過之後args.setPromise(WinJS.UI.processAll());

(function() { 
"use strict"; 

WinJS.Binding.optimizeBindingReferences = true; 

var app = WinJS.Application; 
var activation = Windows.ApplicationModel.Activation; 

app.onactivated = function (args) { 
    if (args.detail.kind === activation.ActivationKind.launch) { 
     if (args.detail.previousExecutionState !== activation.ApplicationExecutionState.terminated) { 
      // TODO: This application has been newly launched. Initialize 
      // your application here. 
     } else { 
      // TODO: This application has been reactivated from suspension. 
      // Restore application state here. 
     } 
     args.setPromise(WinJS.UI.processAll()); 
     $(document).ready(function() { 
      $('#buttonYouWantToClick').click(function() { 
       $('#result').html('jQuery works!'); 
      }); 
     }); 

    } 
}; 
app.oncheckpoint = function (args) { 
    // TODO: This application is about to be suspended. Save any state 
    // that needs to persist across suspensions here. You might use the 
    // WinJS.Application.sessionState object, which is automatically 
    // saved and restored across suspension. If you need to complete an 
    // asynchronous operation before your application is suspended, call 
    // args.setPromise(). 
}; 

app.start(); 
})(); 

在兩個案例不起作用。我得到同樣的錯誤

SCRIPT5009:在MS-APPX線38,列5未處理的異常://a8fcf58a-3cda-4e8c-ae43-733030e738e2/js/default.js 0x800a1391 - JavaScript的運行時錯誤:「$ '未定義 文件:default.js,行:38,列:5 HTML1300:導航發生。 文件:default.html中

APPHOST9623:應用程序無法解析MS-APPX://a8fcf58a-3cda-4e8c-ae43-733030e738e2/js/jquery.js因爲這個錯誤的:RESOURCE_NOT_FOUND。 Visual Studio當前未附加到支持腳本診斷的腳本調試目標。

在此先感謝。

回答

1

jQuery工作正常(某些規定),但是我將根據您發佈的錯誤假設您將該文件添加到磁盤上,但未將其添加到項目中。 它不在你的包中,因此找不到它,所以任何jQuery調用失敗,

點擊「解決方案資源管理器」到「顯示所有文件」並右擊它幷包含在你的項目中,重建並運行再次

我這裏用這個特定的版本沒有問題。

https://github.com/appendto/jquery-win8

我建議密切關注2.0,但如果你想有一個發佈的版本給這一個嘗試

當文本文件不是utf-8編碼時,我也看到一些人有錯誤(你可以打開它並選擇'另存爲',然後選擇下載符號以保存編碼,但我不相信這是一個問題在這裏,只是提供一個參考)

2

看這個博客帖子發佈here

+0

Thanks.But我下載了所有的jQuery庫,並嘗試每一個,並再次得到了同樣的錯誤0x800a1391 - JavaScript運行時錯誤:'$'未定義。 – Karlen

+1

甚至在發佈公告之前@Johannes指出,jQuery當然可以在您描述的錯誤之外運行。該錯誤通常是因爲jquery庫沒有正確加載到您的JavaScript文件中,而不是因爲jQuery本身的問題。發佈一個小樣本,我們可能會提供幫助 –

1

由於2.0版本,jQuery的工作在Windows應用商店的應用程序,爲他人在這裏已經指出。在default.js

<link href="/css/default.css" rel="stylesheet" /> 
<script src="/js/default.js"></script> 
<script src="js/jquery-git2.js"></script> 

隨着下面的小變化:我只是證實了這一點由http://jquery.com/download/下載的jQuery 2.0,拖放到一個新的應用程序

app.onactivated = function (args) { 
    if (args.detail.kind === activation.ActivationKind.launch) { 
     if (args.detail.previousExecutionState !== activation.ApplicationExecutionState.terminated) { 
      $("p").html("App Launched"); 
     } else { 
      $("p").html("App Reactivated from Suspension"); 
     } 
     args.setPromise(WinJS.UI.processAll()); 
    } 
}; 

這工作沒有任何問題。確保你的代碼放在onactivated處理程序中。否則當這段代碼運行時,jQuery可能還沒有可用。

這很可能是您下載jQuery的錯誤副本,或者您沒有將它正確地包含到您的應用程序中。從http://jquery.com/download/

  • 在項目

    1. 下載jQuery的,從/js/js目錄和添加/現有項目右鍵單擊
    2. 將jQuery的文件後刪除它:按照以下步驟default.js參考
    3. 添加內部app.onactivated回調jQuery代碼(見上面的代碼)