问题描述
我收到此错误消息 ReferenceError: $ is not defined when using vscode built-in debugger node.js Here is the html
<html lang="zh-cn"><头><标题>14.jQuery 入门</title><script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><身体><script type="text/javascript" src="js/app.js"></script></html>
这里是 app.js
$(function() {//启动代码在这里警报(这有效!");});
我在警报行设置了一个断点并在 vscode 中运行调试(node.js).它停在 $(function() { - app.js 的第一行,错误信息为 ReferenceError: $ is not defined. 似乎没有加载 jQuery.
我试过了
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></脚本>
和
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></脚本>
但它们都不起作用.请帮忙.
如果你想在 NodeJS 中使用你的 HTML 文件中加载的 jQuery,你需要先将它与 $
关联起来:>
转到要使用它的脚本,然后写入:
window.$ = window.jQuery;
如果这不起作用,请通过在脚本文件夹中打开终端然后键入:
来安装 jQuery npm 包npm i jquery
然后写
window.$ = window.jQuery = require("jquery");
在你的脚本中.
I have this error message ReferenceError: $ is not defined when using vscode built-in debugger node.js Here is the html
<!doctype html>
<html lang="en">
<head>
<title>14. Getting Started with jQuery</title>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<script type="text/javascript" src="js/app.js"></script>
</body>
</html>
Here is the app.js
$(function() {
// start up code goes here
alert("this works!");
});
I put a breakpoint at the alert line and run the debug (node.js) in vscode. It stopped at $(function() { - the first line of app.js with error message of ReferenceError: $ is not defined. Seems like jQuery is not loaded.
I tried
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
and
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
but none of them works. Please help.
If you want to use the jQuery loaded in your HTML file in NodeJS, you need to associate it with $
first:
Go to the script where you want to use it, and write:
window.$ = window.jQuery;
If that does not work, install the jQuery npm package by opening your terminal inside the folder of your script and then typing:
npm i jquery
Then write
window.$ = window.jQuery = require("jquery");
in your script.
这篇关于参考错误:调试时未定义 $的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!