【问题标题】:Keep Getting an Error: 'Uncaught ReferenceError: $ is not defined'不断出现错误:“未捕获的 ReferenceError:$ 未定义”
【发布时间】:2023-04-01 11:45:03
【问题描述】:

尝试将我的输入添加到列表中,但我不断收到错误消息。 谁能帮帮我吗? 代码如下:

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:

$(document).ready(function(){
    $(".add-btn").click(function (){
        var x = $('#item-add').val();
        $(".shop-list").append('x');
    });

});

【问题讨论】:

  • 你是否在页面中包含了 jQuery...
  • 你是否包含了 jquery 文件
  • 如果你认为你已经包含了它,请检查它是否有错别字。
  • 如果包含...您是否使用了noConflict 选项...如果是,请尝试jQuery(document).ready(function($){...});
  • @DavidTrinh:除非你故意混淆,app.js 不是 jQuery。

标签: javascript jquery


【解决方案1】:

您需要包含 jQuery 库。在头部添加这个。

&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"&gt;&lt;/script&gt;

【讨论】:

    【解决方案2】:

    您需要在&lt;script&gt; 标记中包含src 的URL 的https://http:// 部分。光是code.jquery.com/jquery.min.js就找不到了:

    <script src="https://code.jquery.com/jquery.min.js"></script>
    

    还要确保在您的代码之前首先包含 jQuery。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-23
      • 2020-02-02
      • 2021-02-28
      • 2014-10-21
      • 2023-03-04
      • 2019-12-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多