jQuery加载后,为什么我会遇到jQuery参考错误



我在简单的jQuery测试中遇到了错误。请参阅图像以显示文件加载的顺序以及在错误发生之前加载jQuery的事实。

这是我的内容页面:

    <asp:Content
    ID="Content1"
    ContentPlaceHolderID="HeadContent"
    runat="server">
</asp:Content>
<asp:Content
    ID="Content2"
    ContentPlaceHolderID="MainContent"
    runat="server">
    <textarea id="txtArea"> hi </textarea>
    <script type="text/javascript">
        // Shorthand for $( document ).ready()
        $(function () {
            $('txtArea').val = "bye";
        });
    </script>
</asp:Content>

我在主页的末尾,在关闭标签之前加载了我的脚本。

有人知道是什么原因导致了这个简单的错误?

我不认为我的图像在上传。这是显示库已加载的火焰结果。

GET TestFolder/TestLoadingScriptsFromDifferentFolderLevel.aspx [HTTP/1.1 200 OK 1351ms]
GET Styles/Site.css [HTTP/1.1 200 OK 4ms]
GET WebResource.axd [HTTP/1.1 200 OK 351ms]
GET http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.1.0.min.js [HTTP/1.1 200 OK 405ms]
GET http://ajax.aspnetcdn.com/ajax/jquery.ui/1.10.3/jquery-ui.min.js [HTTP/1.1 200 OK 417ms]
GET http://ajax.aspnetcdn.com/ajax/jquery.ui/1.10.3/themes/le-frog/jquery-ui.css [HTTP/1.1 200 OK 338ms]
GET http://ajax.aspnetcdn.com/ajax/jquery.ui/1.10.3/themes/mint-choc/jquery-ui.css [HTTP/1.1 200 OK 285ms]
GET http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js [HTTP/1.1 200 OK 394ms]
GET http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/additional-methods.min.js [HTTP/1.1 200 OK 380ms]
GET http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/jquery.dataTables.min.js [HTTP/1.1 200 OK 419ms]
GET http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/css/jquery.dataTables.css [HTTP/1.1 200 OK 61ms]
GET http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/css/jquery.dataTables_themeroller.css [HTTP/1.1 200 OK 57ms]
GET http://ajax.aspnetcdn.com/ajax/knockout/knockout-3.0.0.debug.js [HTTP/1.1 200 OK 129ms]
ReferenceError: $ is not defined TestLoadingScriptsFromDifferentFolderLevel.aspx:45
GET WebResource.axd [HTTP/1.1 200 OK 2ms]

line"我的脚本在主页的末尾加载,然后在关闭标签之前。"让我认为您的问题是您的问题。

将脚本加载到主页顶部的顶部,这将解决您的问题。

最新更新