这是我的 default.html 文件
<!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 文件。我把jquery
代码放在app.start()
函数之前。
...
$(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://a8fcf58a-3cda-4e8c-ae43-733030e738e2/js/default.js 0x800a1391 第 38 行第 5 列未处理的异常 - JavaScript 运行时错误:'$' 未定义文件:default.js,行:38,列:5 HTML1300:发生导航。文件:default.html
APPHOST9623:应用程序无法解析 ms-appx://a8fcf58a-3cda-4e8c-ae43-733030e738e2/js/jquery.js,因为此错误:RESOURCE_NOT_FOUND。Visual Studio 当前未附加到支持脚本诊断的脚本调试目标。
提前致谢。