My code works when I write the JS in HTML like so:
(当我用HTML编写JS时,我的代码可以正常工作,如下所示:)
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<title>Address Book</title>
</head>
<body>
<input id="submitButton" type = "submit" value = "Save">
<script>
$("#submitButton").on("click", function() {
console.log("result!");
});
</script>
</body>
but when I split it out into it's own .js file, the JS file doesn't recognise the JQuery '$' sign.
(但是当我将其拆分成自己的.js文件时,JS文件无法识别JQuery的“ $”符号。)
This is how it currently looks in both HTML and JS (I added the .JS source to the HTML file): (这是当前在HTML和JS中的外观(我将.JS源添加到HTML文件中):)
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
**<script type="text/javascript" src="addressBook.js"></script>**
<title>Address Book</title>
</head>
<body>
<input id="submitButton" type = "submit" value = "Save">
</body>
and in the addressBook.js file:
(并在addressBook.js文件中:)
$("#submitButton").on("click", function() {
console.log("omg, you clicked me!");
I get the following error logged to the console when i click the button:
(单击按钮时,我将以下错误记录到控制台:)
$("#submitButton").on("click", function() { ^ ReferenceError: $ is not defined
($(“#submitButton”)。on(“ click”,function(){^ ReferenceError:$未定义)
Any help would be appreciated!
(任何帮助,将不胜感激!)
Thanks
(谢谢)
ask by MattCouthon translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…