如何解决ReferenceError:未定义$ [jQuery] [CEF]
我正在学习HTML和JavaScript,但遇到此错误:ReferenceError: $ is not defined
。我已经收到此错误,并被告知要在<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
上添加<head>
。
我还被告知要确保所有jQuery javascript代码都在以下代码块中运行:
$(document).ready(function () {
//your code here
});
我这样做了。但是,我仍然遇到相同的错误。
那是什么原因呢?我使用的版本错误吗?怎么了?这是完整的代码:
html.html
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="common.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<body>
<div class="org-bar">
<h1 style="font-size:20px;">Criar Organização</h2>
<form id="orgCreation" action="welcome.php" method="post"></form>>
<label for="orgName"></label>
<input class="textInput" type="text" id="orgName" name="orgName" placeholder="Nome da Organização [5-20]" minlength="5" maxlength="20">
<label for="orgAbb"></label>
<input class="textInput" type="text" id="orgAbb" name="orgAbb" placeholder="Abreviatura da Organização [3-4]" minlength="3" maxlength="4">
<input class="button" type="button" id="orgButton" value="Criar">
</div>
</form>
</div>
<script src="orgcreation.js" type="text/javascript"></script>
</body>
</html>
您可以看到我首先在头上调用jQuery,然后仅在正文底部调用javascript文件。 orgcreation.js
$(document).ready(function(){
$("orgButton").click(function(){
mp.trigger('orgCreation',$('#orgName').val(),$('#orgAbb').val());
});
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。