WebStorm ReferenceError: $ is not defined
WebStorm ReferenceError: $ is not defined
所以我在 WebStorm 中编译时出现了这个错误:
(function (exports, require, module, __filename, __dirname) { $(function () {
ReferenceError: $ is not defined
似乎 jQuery 没有正确加载。这是我的 HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
</script>
<script type="text/javascript" src="AlexTypescript.js"></script>
</head>
<body>
<div>
<button id="BtnBC">
Change BC
</button>
</div>
</body>
</html>
这是我的功能:
$(function () {
$("#BtnBC").on("click", function () {
$("body").css("background-color", "black");
});
});
我创建了一个简单的按钮来检查它是否正常工作。这是。我只是在 WebStorm 中编译时收到一条错误消息。
到目前为止我做了什么:
1) Clean installation of the IDE, nodejs, modules etc.
2) Checking the referenced path of jQuery and that it is loaded before the .js file
3) Referencing a local jQuery installation as well as the CDN
4) Writing jQuery instead of $
我对编码还很陌生,所以非常感谢您的帮助:)
尝试更改,美元符号($
)只是jQuery
的别名,其他框架和库可以使用$
。
jQuery(function ($) {
$("#BtnBC").on("click", function () {
$("body").css("background-color", "black");
});
});
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
</script>
<script type="text/javascript" src="AlexTypescript.js"></script>
</head>
<body>
<div>
<button id="BtnBC">
Change BC
</button>
</div>
</body>
</html>
所以我在 WebStorm 中编译时出现了这个错误:
(function (exports, require, module, __filename, __dirname) { $(function () {
ReferenceError: $ is not defined
似乎 jQuery 没有正确加载。这是我的 HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
</script>
<script type="text/javascript" src="AlexTypescript.js"></script>
</head>
<body>
<div>
<button id="BtnBC">
Change BC
</button>
</div>
</body>
</html>
这是我的功能:
$(function () {
$("#BtnBC").on("click", function () {
$("body").css("background-color", "black");
});
});
我创建了一个简单的按钮来检查它是否正常工作。这是。我只是在 WebStorm 中编译时收到一条错误消息。
到目前为止我做了什么:
1) Clean installation of the IDE, nodejs, modules etc.
2) Checking the referenced path of jQuery and that it is loaded before the .js file
3) Referencing a local jQuery installation as well as the CDN
4) Writing jQuery instead of $
我对编码还很陌生,所以非常感谢您的帮助:)
尝试更改,美元符号($
)只是jQuery
的别名,其他框架和库可以使用$
。
jQuery(function ($) {
$("#BtnBC").on("click", function () {
$("body").css("background-color", "black");
});
});
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
</script>
<script type="text/javascript" src="AlexTypescript.js"></script>
</head>
<body>
<div>
<button id="BtnBC">
Change BC
</button>
</div>
</body>
</html>