JavaScript运行时错误:'$';在Windows应用程序开发中未定义
我正在使用Visual Studio开发一个Windows 8.1应用程序,使用HTML、CSS、jQuery(允许使用JavaScript),正如我在下面的博客中读到的那样,我也可以使用jQuery开发该应用程序 因此,我在HTML页面中也包含了jQuery 2.1.0文件,如下所示:JavaScript运行时错误:'$';在Windows应用程序开发中未定义,javascript,jquery,html,windows,Javascript,Jquery,Html,Windows,我正在使用Visual Studio开发一个Windows 8.1应用程序,使用HTML、CSS、jQuery(允许使用JavaScript),正如我在下面的博客中读到的那样,我也可以使用jQuery开发该应用程序 因此,我在HTML页面中也包含了jQuery 2.1.0文件,如下所示: <script src="/js/jquery-2.1.0.js"></script> 但是,我怎么能在这个js函数中使用jQuery代码呢?因为我不知道,而且我搜索的每一篇博文都有
<script src="/js/jquery-2.1.0.js"></script>
但是,我怎么能在这个js函数中使用jQuery代码呢?因为我不知道,而且我搜索的每一篇博文都有教程告诉我jQuery代码的用法,而不是如何实现它或者如何定义$
字符
谢谢 如果jQuery库链接不正确,则jQuery指令$未定义
确保你在页面顶部链接了它,在其他所有内容之前,先在页面头部链接它,并确保你的相对路径是正确的。也许你与其他内容有冲突?请看这里,看看它是否有帮助。我在看到您的附加图像后发现,您包含jQuery但不在顶部。对于jQuery,如果在使用jQuery文件之前加载了jQuery文件,则将定义$。因此,将jQuery文件移到顶部可以解决这个问题
$是在jQuery中定义的。您是否在脚本之前包含jQuery脚本文件?是的,我已经包含了…但是,您可以将其作为第一个脚本移动。将jQuery链接移动到第一个脚本。是的,很重要。在jQuery之前,您已经包含了default.js,我有一种奇怪的感觉,在default.js脚本中有jQuery代码,将jQuery置于一切之上,并看到您的问题得到了解决。然后,您可能在另一个链接脚本中包含了jQuery代码。JQuery必须是最顶层的:如果我的答案有帮助,请考虑接受它^ ^ ^ ^好。可视化编辑器!;)
// For an introduction to the Blank template, see the following documentation:
// http://go.microsoft.com/fwlink/?LinkId=232509
(function () {
"use strict";
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());
}
};
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().
};
$('p').click(function () { /* <---- from here */
$(this).html('Some text! hehehe..Sorry!');
});
app.start();
})();
$(document).ready(function() {
/* '$' will be defined in this block */
}