[英]Keep Getting an Error: 'Uncaught ReferenceError: $ is not defined'
Trying to add my input onto a list but I keep getting an error. 尝试将我的输入添加到列表中,但我不断收到错误消息。 Can anyone please help me? 谁能帮帮我吗? Here is the code: 这是代码:
HTML: HTML:
<div class="add-item">
<input id="item-add" type='text' placeholder="Enter item to shopping list..." name="itemAdd"></input>
<button class="add-btn">Add Item</button>
</div>
<div class="item-list">
<H2>Shopping List</H2>
<ul class="shop-list">
<li><input type="checkbox">Item 1</li>
<li><input type="checkbox">Item 2</li>
<li><input type="checkbox">Item 3</li>
<li><input type="checkbox">Item 4</li>
<li><input type="checkbox">Item 5</li>
</ul>
</div>
jQuery: jQuery的:
$(document).ready(function(){
$(".add-btn").click(function (){
var x = $('#item-add').val();
$(".shop-list").append('x');
});
});
You need to include the jQuery library. 您需要包括jQuery库。 Add this in the head section. 将其添加到头部。
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
You need to include the https://
or http://
part of the URL for a src
in the <script>
tag. 您需要在<script>
标记中包含src
的URL的https://
或http://
部分。 Simply code.jquery.com/jquery.min.js
will not find it: 只是code.jquery.com/jquery.min.js
找不到它:
<script src="https://code.jquery.com/jquery.min.js"></script>
Also make sure jQuery is included first, before your code. 还要确保在代码之前首先包含jQuery。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.