javascript - 未捕获的引用错误 $ 未定义......请帮助我

标签 javascript jquery

我一直在尝试编写一个应用程序,但不断收到“ Uncaught ReferenceError :$未定义”。这让我发疯,我检查了好几次代码,却无法找出问题所在。任何人都可以看到问题吗?我对此很陌生,因此非常感谢我能得到的所有帮助!干杯......

HTML

        <!DOCTYPE html>
        <html>
            <head>
                <title> SNAP THAT SWEET DINNER </title>
                    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">

                    <link rel="stylesheet" type="text/css" href="style.css">

            </head>

            <body>
                <section>
                    <canvas id="1">Canvas not supported</canvas>
                    <h1> Snap that free dinner! </h1>

                        <p>Player Paul</p>
                        <p>Player Ant</p>

                    <canvas id="2">Canvas not supported</canvas>    



                </section>

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

                    <script src="script.js"></script>

            </body> 




        </html

CSS:

 body {
        text-align: center;
        font-family: Helvetica;
        background: lightGrey;
    }

    canvas{
        width: 100%;
        height: 42%;
        background-color: yellow;
        border-radius: 15px;
        background-image: url("https://c1.staticflickr.com/1/55/139721356_a7748d8928_z.jpg?zz=1/image1.jpg");
        background-size: cover;
        background-position: centre;
    }


    html, body, section {
    height: 100%; 
    }

    h1{
        background: yellow;
        padding: 2%;
        margin: 2%;
        border: 2px solid black;
        border-radius: 40px;
    }

    p{
        width:40%;
        float: left;
        padding: 2%;
        margin: 2%;
        border: 2px solid black;
        border-radius: 40px;
        display: none;
    }

JS

// Define images to use
var imgArray = ["https://c1.staticflickr.com/1/206/447644669_27b7db7bf6_z.jpg?zz=1/image1.jpg", "https://c1.staticflickr.com/1/55/139721356_a7748d8928_z.jpg?zz=1/image2.jpg", "https://c2.staticflickr.com/4/3947/15679809871_aa34830ebc_z.jpg,image3.jpg", "https://c2.staticflickr.com/6/5166/5279373536_522839f447_b.jpg/image4.jpg", "http://christmasstockimages.com/free/food-dining/slides/raw_uncooked_turkey.jpg/image5.jpg"];
//create number variable
var num1;
var num2;
//randomly change number
num1 = Math.floor( Math.random() * imgArray.length );
num2 = Math.floor( Math.random() * imgArray.length );
//test random numbers
console.log("first random number is" +num1);
console.log("second random number is" +num2);
//create image variables
var img1 = imgArray[ num1 ];
var img2 = imgArray[ num2 ];
//create css value for background image
var url1 = "url("+ img1 +")";
var url2 = "url("+ img2 +")";

//use jquery to change background image
$("canvas#1").css("background-image", url1);
$("canvas#2").css("background-image", url2);

最佳答案

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

关于javascript - 未捕获的引用错误 $ 未定义......请帮助我,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28707852/

相关文章:

javascript - jQuery 问题

javascript - JavaScript 拆分如何处理阿拉伯语和英语数字字符串?

php - 发送全局变量

javascript - 数组作为参数传递,但函数内重新分配失败?

javascript - 通过单击 jquery 中的链接打开新选项卡(窗口)

c# - 从外部javascript文件获取用户控件中的clientid

JQuery 动画边框而不移动 div

jquery - 负载上的元素过滤

javascript - jQuery Mobile - 使用 URL 参数打开可折叠集

javascript - 未捕获的 token : when want to get json by ajax