JavaScript 运行时错误:“$"未定义 [英] JavaScript runtime error: '$' is undefined

查看:40
本文介绍了JavaScript 运行时错误:“$"未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如此经典的问题,但在寻找实际原因方面却花费了大量时间.通常,当我看到此错误时,是因为 jQuery 引用在需要它的代码之后,或返回 jQuery 链接,或 jQuery 冲突等......到目前为止,这些似乎都不是这种情况.不幸的是,寻找这个问题的解决方案让我发了一个又一个这样的案例.我确定我的问题同样简单,但经过一个多小时的狩猎,仍然没有运气......

So classic problem, but having a horrible time on finding the actual cause. Typically when I see this error it's because the jQuery reference is after code requiring it, or back jQuery link, or jQuery conflict, etc... so far none of those appear to be the case. Unfortunately seeking out the solution to this problem has lead me to post after post of such cases. I'm sure my problem here is equally as simple, but over an hour of hunting, still no luck...

附加信息...解决方案文件(我已经多次重新创建以试图解决这个问题.是一个 JavaScript Windows Store Blank App 模板,我正在 Visual Studio 中执行此操作.唯一的参考文件是 Windows Library for javascript 1.0,我尝试删除这也是为了测试.

Additional information... The solution file (which I've recreated multiple times trying to figure this out. Is a JavaScript Windows Store Blank App template and I'm doing this in Visual studio. The only references files is Windows Library for javascript 1.0, I have tried deleting this to test as well.

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title>HTML5 Canvas Template</title>
        <style>
            /* styles here */
        </style>
    </head>
    <body>
        <canvas id="myCanvas" width="500" height="500">
            <p>Canvas not supported.</p>
        </canvas>

        <script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
        <script type="text/javascript">
            $(document).ready(function() {
                var canvas = $("#myCanvas").get(0);
                var context = canvas.getContext("2d");

                function renderContent()
                {
                    // we'll do our drawing here...
                }

                renderContent();
            });
        </script>
</body>
</html>

推荐答案

它指出 JQuery 引用的 URL 不正确

It's states that JQuery referred URL is not correct

试试这个:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

这篇关于JavaScript 运行时错误:“$"未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆