未被引用的引用错误$未定义.....请帮助我

时间:2015-02-24 22:44:19

标签: 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);

1 个答案:

答案 0 :(得分:4)

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