2013-04-13 52 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代码(见上面的代码)