问题描述
我正在学习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 (将#修改为@)