未捕获的引用错误:未定义 jQuery

Uncaught ReferenceError: jQuery is not defined

本文关键字:未定义 jQuery 错误 引用      更新时间:2023-09-26

我不明白为什么我会得到这个,下面的代码:

<head>
            <script src="https://code.jquery.com/color/jquery.color-2.1.2.min.js" type="text/javascript"></script>
            <script>
                var json1 = {
                text: "After first paragraph"
                };

                var first_content_added = false;

                $(function() {
                $(".learn-more").on("click", function() {
                $.getJSON("json_info.json", function(data) {
                appendContentToFirstP(data.reviews[0].about.moreinfo);
                });
                });
                });
                function appendContentToFirstP(content) {
                if (first_content_added) {
                return;
                }
                var after_first_p = $('<p class="more-info" />');

                after_first_p.text(content);

                $(".first").append(after_first_p);

                first_content_added = true;
                }

            </script>
</head>

导致错误的原因是什么?我最初的想法是错误是因为我没有导入 JQuery,但我有。它位于顶部的脚本标记内。

没有包含 jQuery,你只包含了插件 jQuery.color。

在jQuery.color之前引用它:

<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>

像这样写颜色 js

    <script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
    <script src="https://code.jquery.com/color/jquery.color-2.1.2.min.js" type="text/javascript"></script>