Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Can';t在on函数中更改id的值_Javascript_Jquery - Fatal编程技术网

Javascript Can';t在on函数中更改id的值

Javascript Can';t在on函数中更改id的值,javascript,jquery,Javascript,Jquery,我想在“on”函数中用id更改的值,但它不会更改 <div id="boardGame"> </div> <script type="text/javascript"> json_dic = {"Too Much to Ask": "oHRjgi6sniY", "Sketchead": "GEfpkuCPjXs", "If You Were There, Beware": "ZVOwOzL9uDQ", "Plastic Tramp": "BiVXU

我想在“on”函数中用
id
更改
的值,但它不会更改

<div id="boardGame">
</div>

<script type="text/javascript">

    json_dic = {"Too Much to Ask": "oHRjgi6sniY", "Sketchead": "GEfpkuCPjXs", "If You Were There, Beware": "ZVOwOzL9uDQ", "Plastic Tramp": "BiVXU2jt1Xo", "The Death Ramps": "p7cijGnXUJM", "Don't Sit Down 'Cause I've Moved Your Chair": "h1vYbHHhqYE", "R U Mine?": "VQH8ZTgna3Q", "2013": "O4vkZUC4VPA", "The Bakery": "P_D1Eqa2Lk4", "Potion Approaching": "Urw780t52zc", "Still Take You Home": "FKPKSK1nCKY", "Chun-Li's Spinning Bird Kick": "4lOdBxVS16o", "Come Together": "a-5tTz8flYI", "Snap Out of It": "PHoSRT2fNME", "Cigarette Smoker Fiona": "Wg89x455WK4", "Why'd You Only Call Me When You're High?": "6366dxFf-Os", "Brick by Brick": "qOTRx3ZqjjI", "Temptation Greets You Like Your Naughty Friend ": "VEWNOzgnmq0", "The Blond-O-Sonic Shimmer Trap": "EyBrLYN2Yok", "The Bad Thing": "3xTHjLf-ONg", "All My Own Stunts": "Er3r_J-mwII", "Love Is a Laserquest": "wxQVpRSxOZ0", "Dance Little Liar": "hf-B3Y3B0TQ", "Mardy Bum": "Lp1fQ51YZMM", "Stickin' to the Floor": "AQVMJkZGpSc", "Only Ones Who Know": "m-seRFY7-cw", "Crying Lightning": "fLsBJPlGIDU", "From the Ritz to the Rubble ": "givRh52Ic3A", "I.D.S.T.": "V6yORYEiLyU", "She's Thunderstorms": "tvHz5Rti0cU", "Catapult": "U3LsJMLWN2k", "Stop the World I Wanna Get Off with You": "3PyoxMSEHYI", "The Hellcat Spangled Shalalala": "dAlRXC19hmE", "Do I Wanna Know?": "bpOSxM0rNPM", "Knee Socks": "00bk5E7gecI", "That's Where You're Wrong": "tLOUVbemjro", "Leave Before the Lights Come On": "SEukS2YN9B8", "I Want It All": "SDTxuAEPfdY", "Secret Door": "ibyGhbvo94Q", "Suck It and See": "rjFGapDkSM0", "7": "R2t6vgC_OWw", "Brianstorm": "30w8DyEJ__0", "Baby I'm Yours": "EDLhMf6voq8", "Arabella": "Nj8r3qmOoZ8", "Old Yellow Bricks": "xLaeOrDmWQ4", "Don't Forget Whose Legs You're On": "qL0Z3Ly0CEw", "Riot Van": "j052-ROwPFM", "What If You Were Right the First Time?": "t2cFvzmqmwc", "Fire and the Thud": "VGlhSSP4nTk", "I Wanna Be Yours": "Y4NGoS330HE", "Mad Sounds": "J_-FwyoeV3E", "Fireside": "PG8yTUeptFU", "The Afternoon's Hat": "qbNKclt42Xc", "Reckless Serenade": "PY2FQ-LgmYo", "No Buses": "WK4wISbGvJw", "Electricity": "g-cukZ10j8A", "Little Illusion Machine (Wirral Riddler) ": "WlMzuzud8U4", "Piledriver Waltz": "njirT4N-JxU", "When the Sun Goes Down": "EqkBRVukQmE", "No. 1 Party Anthem": "83hFiC-siDs", "Evil Twin": "xwir-pg7WiA", "This House Is a Circus": "oDB-MGsWzQQ", "I Haven't Got My Strange": "a9yrz_psfLc", "Black Treacle": "1wznj4lD1Bs", "505": "ifZfUVp2chE", "Dangerous Animals": "qHe3E366_Po", "Perhaps Vampires Is a Bit Strong But..": "SjzOUf0AEiQ", "Fluorescent Adolescent": "ma9I9VBKPiw", "Library Pictures": "bmVerkoFPJU", "The View from the Afternoon": "PeQAZsyucbQ", "Despair in the Departure Lounge": "ZLS8ffCYN80", "I Bet You Look Good on the Dancefloor": "pK7egZaT3hs", "Bigger Boys and Stolen Sweethearts": "rLkikLrImnk", "Balaclava": "6LBCqG0YnTM", "Fake Tales of San Francisco": "ePg1tbia9Bg", "D Is for Dangerous": "zOlhvxPC3MQ", "Put Your Dukes Up John": "O8Wuv1WKldk", "My Propeller": "Z5vZovv8cPk", "Red Right Hand": "hcvGOUuDGXc", "One for the Road": "qN7gSMPQFss", "Joining the Dots": "wkvUl_l3o1c", "Red Light Indicates Doors Are Secured": "hdmR58BIHOg", "You and I ": "9zXkAaoBOLU", "Teddy Picker": "2A2XBoxtcUA", "Settle for a Draw": "IQ7NH2jcAAw", "Bad Woman ": "YnkJHU3qYIA", "Cornerstone": "LIQz6zZi7R0", "Fright Lined Dining Room": "qrqtD4TiO5c", "A Certain Romance": "WGyj5JyA5Ms", "If You Found This It's Probably Too Late": "SqKl1vcmvOU", "Who the Fuck Are Arctic Monkeys?": "oFeuKVkau6U", "Do Me a Favour": "lXJEDlLepD4", "You Probably Couldn't See for the Lights but You Were Staring Straight at Me": "j8iV3tK717s", "Dancing Shoes": "3aQELo7tXyI", "The Jeweller's Hands": "1rq0Ag15sAI", "Matador/Da Frame 2R": "DxoPxvJ0FNM", "Pretty Visitors": "4n7iaY22Do0", "You're So Dark": "6eoAwXkI3RA"}

    var score = 0
    var nb = 0
    var iter = 0
    var song
    var start
    var click
    var listSongs = []

    getHome()

    $(document).on("click", '.calc_btn', function() {

        iter++
        $("#valueIter").html(iter+"/10")
        if(iter == 10)
        {
            gameOver(score)
        }
        else 
        {
            click = new Date()
            time = (click.getTime() - start.getTime())/1000
            if($(this).val() == song){
                if(time <= 15)
                    score += parseInt((-1000/14)*time+929)
                $("#valueScore").html(score)
                $("#valueScore").css( "color", "green" )
            } 
            else
            {
                $("#valueScore").html(score)
                $("#valueScore").css( "color", "red" )
            }
            nb += 1
            getSong()
        }
    })

    function getHome()
    {
        score = 0
        iter = 0
        listSongs = []
        $("#boardGame").html("<h2>Welcome to The Game of Monkeys</h2><table class='calculatrice' id='calc'><tbody><tr><td class='calc_td_btn'><input type='button' class='stres' value='Start' onclick='getSong()'></td></tr></tbody></table")
    }

    function getSong()
    {
        var keys = [];
        for (var prop in json_dic) {
            if (json_dic.hasOwnProperty(prop)) {
                keys.push(prop);
            }
        }

        song = keys[ keys.length * Math.random() << 0 ];
        listSongs = [ song ]
        url = json_dic[song]

        while(listSongs.length <= 4)
        {
            var keys = [];
            for (var prop in json_dic) {
                if (json_dic.hasOwnProperty(prop)) {
                    keys.push(prop);
                }
            }

            song_random = keys[ keys.length * Math.random() << 0 ];
            listSongs.push(song_random)
        }

        $("#boardGame").html('<table class="calculatrice" id="calc"> '+
            '<tbody>' +
            '<tr>' +
            '<td class="calc_td_btn">' +
            '<div style="position:relative;width:380px;height:25px;overflow:hidden;">' +
            '<div id="yt_video" style="position:absolute;top:-276px;left:-5px">' +
            '</div>' +
            '</div>' +
            '</td>' +
            '</tr>');

        for(var i = 0; i <= 4; i++)
        {
            var randomIndex = Math.floor(Math.random() * listSongs.length);
            var randomString = listSongs[randomIndex];
            $("#boardGame").append('<tr>'+
                '<td class="calc_td_btn">' +
                '<input type="button" class="calc_btn" value="'+randomString+'">' +
                '</td>' +
                '</tr>')
            var index = listSongs.indexOf(randomString);
            listSongs.splice(index, 1);
        }

        $("#boardGame").append('<tr>' +
            '<td class="calc_td_btn">' +
            '<h2 id="valueScore">0 points</h2>' +
            '<h2 id="valueIter">0/10</h2>' +
            '<input type="button" class="stres" onclick="getHome()" value="Restart">' +
            '</td>' +
            '</tr>' +
            '</tbody>' +
            '</table>')

        var nb = getRandomInt(0,100)
        $("#yt_video").html("<iframe src='https://www.youtube.com/embed/"+url+"?autoplay=0&start="+nb+"' id='yt_video' width='380' height='300'></iframe>")

        start = new Date()

    }

    function getRandomInt (min, max) {
        return Math.floor(Math.random() * (max - min + 1)) + min;
    }

    function gameOver(score){
        $("#boardGame").html("<h2>You scored "+score+" points</h2><table class='calculatrice' id='calc'><tbody><tr><td class='calc_td_btn'><input type='button' onclick='getHome()' class='stres' value='Restart'></td></tr></tbody></table")
    }

</script>




</body>
</html>
代码如下:

<div id="boardGame">
</div>

<script type="text/javascript">

    json_dic = {"Too Much to Ask": "oHRjgi6sniY", "Sketchead": "GEfpkuCPjXs", "If You Were There, Beware": "ZVOwOzL9uDQ", "Plastic Tramp": "BiVXU2jt1Xo", "The Death Ramps": "p7cijGnXUJM", "Don't Sit Down 'Cause I've Moved Your Chair": "h1vYbHHhqYE", "R U Mine?": "VQH8ZTgna3Q", "2013": "O4vkZUC4VPA", "The Bakery": "P_D1Eqa2Lk4", "Potion Approaching": "Urw780t52zc", "Still Take You Home": "FKPKSK1nCKY", "Chun-Li's Spinning Bird Kick": "4lOdBxVS16o", "Come Together": "a-5tTz8flYI", "Snap Out of It": "PHoSRT2fNME", "Cigarette Smoker Fiona": "Wg89x455WK4", "Why'd You Only Call Me When You're High?": "6366dxFf-Os", "Brick by Brick": "qOTRx3ZqjjI", "Temptation Greets You Like Your Naughty Friend ": "VEWNOzgnmq0", "The Blond-O-Sonic Shimmer Trap": "EyBrLYN2Yok", "The Bad Thing": "3xTHjLf-ONg", "All My Own Stunts": "Er3r_J-mwII", "Love Is a Laserquest": "wxQVpRSxOZ0", "Dance Little Liar": "hf-B3Y3B0TQ", "Mardy Bum": "Lp1fQ51YZMM", "Stickin' to the Floor": "AQVMJkZGpSc", "Only Ones Who Know": "m-seRFY7-cw", "Crying Lightning": "fLsBJPlGIDU", "From the Ritz to the Rubble ": "givRh52Ic3A", "I.D.S.T.": "V6yORYEiLyU", "She's Thunderstorms": "tvHz5Rti0cU", "Catapult": "U3LsJMLWN2k", "Stop the World I Wanna Get Off with You": "3PyoxMSEHYI", "The Hellcat Spangled Shalalala": "dAlRXC19hmE", "Do I Wanna Know?": "bpOSxM0rNPM", "Knee Socks": "00bk5E7gecI", "That's Where You're Wrong": "tLOUVbemjro", "Leave Before the Lights Come On": "SEukS2YN9B8", "I Want It All": "SDTxuAEPfdY", "Secret Door": "ibyGhbvo94Q", "Suck It and See": "rjFGapDkSM0", "7": "R2t6vgC_OWw", "Brianstorm": "30w8DyEJ__0", "Baby I'm Yours": "EDLhMf6voq8", "Arabella": "Nj8r3qmOoZ8", "Old Yellow Bricks": "xLaeOrDmWQ4", "Don't Forget Whose Legs You're On": "qL0Z3Ly0CEw", "Riot Van": "j052-ROwPFM", "What If You Were Right the First Time?": "t2cFvzmqmwc", "Fire and the Thud": "VGlhSSP4nTk", "I Wanna Be Yours": "Y4NGoS330HE", "Mad Sounds": "J_-FwyoeV3E", "Fireside": "PG8yTUeptFU", "The Afternoon's Hat": "qbNKclt42Xc", "Reckless Serenade": "PY2FQ-LgmYo", "No Buses": "WK4wISbGvJw", "Electricity": "g-cukZ10j8A", "Little Illusion Machine (Wirral Riddler) ": "WlMzuzud8U4", "Piledriver Waltz": "njirT4N-JxU", "When the Sun Goes Down": "EqkBRVukQmE", "No. 1 Party Anthem": "83hFiC-siDs", "Evil Twin": "xwir-pg7WiA", "This House Is a Circus": "oDB-MGsWzQQ", "I Haven't Got My Strange": "a9yrz_psfLc", "Black Treacle": "1wznj4lD1Bs", "505": "ifZfUVp2chE", "Dangerous Animals": "qHe3E366_Po", "Perhaps Vampires Is a Bit Strong But..": "SjzOUf0AEiQ", "Fluorescent Adolescent": "ma9I9VBKPiw", "Library Pictures": "bmVerkoFPJU", "The View from the Afternoon": "PeQAZsyucbQ", "Despair in the Departure Lounge": "ZLS8ffCYN80", "I Bet You Look Good on the Dancefloor": "pK7egZaT3hs", "Bigger Boys and Stolen Sweethearts": "rLkikLrImnk", "Balaclava": "6LBCqG0YnTM", "Fake Tales of San Francisco": "ePg1tbia9Bg", "D Is for Dangerous": "zOlhvxPC3MQ", "Put Your Dukes Up John": "O8Wuv1WKldk", "My Propeller": "Z5vZovv8cPk", "Red Right Hand": "hcvGOUuDGXc", "One for the Road": "qN7gSMPQFss", "Joining the Dots": "wkvUl_l3o1c", "Red Light Indicates Doors Are Secured": "hdmR58BIHOg", "You and I ": "9zXkAaoBOLU", "Teddy Picker": "2A2XBoxtcUA", "Settle for a Draw": "IQ7NH2jcAAw", "Bad Woman ": "YnkJHU3qYIA", "Cornerstone": "LIQz6zZi7R0", "Fright Lined Dining Room": "qrqtD4TiO5c", "A Certain Romance": "WGyj5JyA5Ms", "If You Found This It's Probably Too Late": "SqKl1vcmvOU", "Who the Fuck Are Arctic Monkeys?": "oFeuKVkau6U", "Do Me a Favour": "lXJEDlLepD4", "You Probably Couldn't See for the Lights but You Were Staring Straight at Me": "j8iV3tK717s", "Dancing Shoes": "3aQELo7tXyI", "The Jeweller's Hands": "1rq0Ag15sAI", "Matador/Da Frame 2R": "DxoPxvJ0FNM", "Pretty Visitors": "4n7iaY22Do0", "You're So Dark": "6eoAwXkI3RA"}

    var score = 0
    var nb = 0
    var iter = 0
    var song
    var start
    var click
    var listSongs = []

    getHome()

    $(document).on("click", '.calc_btn', function() {

        iter++
        $("#valueIter").html(iter+"/10")
        if(iter == 10)
        {
            gameOver(score)
        }
        else 
        {
            click = new Date()
            time = (click.getTime() - start.getTime())/1000
            if($(this).val() == song){
                if(time <= 15)
                    score += parseInt((-1000/14)*time+929)
                $("#valueScore").html(score)
                $("#valueScore").css( "color", "green" )
            } 
            else
            {
                $("#valueScore").html(score)
                $("#valueScore").css( "color", "red" )
            }
            nb += 1
            getSong()
        }
    })

    function getHome()
    {
        score = 0
        iter = 0
        listSongs = []
        $("#boardGame").html("<h2>Welcome to The Game of Monkeys</h2><table class='calculatrice' id='calc'><tbody><tr><td class='calc_td_btn'><input type='button' class='stres' value='Start' onclick='getSong()'></td></tr></tbody></table")
    }

    function getSong()
    {
        var keys = [];
        for (var prop in json_dic) {
            if (json_dic.hasOwnProperty(prop)) {
                keys.push(prop);
            }
        }

        song = keys[ keys.length * Math.random() << 0 ];
        listSongs = [ song ]
        url = json_dic[song]

        while(listSongs.length <= 4)
        {
            var keys = [];
            for (var prop in json_dic) {
                if (json_dic.hasOwnProperty(prop)) {
                    keys.push(prop);
                }
            }

            song_random = keys[ keys.length * Math.random() << 0 ];
            listSongs.push(song_random)
        }

        $("#boardGame").html('<table class="calculatrice" id="calc"> '+
            '<tbody>' +
            '<tr>' +
            '<td class="calc_td_btn">' +
            '<div style="position:relative;width:380px;height:25px;overflow:hidden;">' +
            '<div id="yt_video" style="position:absolute;top:-276px;left:-5px">' +
            '</div>' +
            '</div>' +
            '</td>' +
            '</tr>');

        for(var i = 0; i <= 4; i++)
        {
            var randomIndex = Math.floor(Math.random() * listSongs.length);
            var randomString = listSongs[randomIndex];
            $("#boardGame").append('<tr>'+
                '<td class="calc_td_btn">' +
                '<input type="button" class="calc_btn" value="'+randomString+'">' +
                '</td>' +
                '</tr>')
            var index = listSongs.indexOf(randomString);
            listSongs.splice(index, 1);
        }

        $("#boardGame").append('<tr>' +
            '<td class="calc_td_btn">' +
            '<h2 id="valueScore">0 points</h2>' +
            '<h2 id="valueIter">0/10</h2>' +
            '<input type="button" class="stres" onclick="getHome()" value="Restart">' +
            '</td>' +
            '</tr>' +
            '</tbody>' +
            '</table>')

        var nb = getRandomInt(0,100)
        $("#yt_video").html("<iframe src='https://www.youtube.com/embed/"+url+"?autoplay=0&start="+nb+"' id='yt_video' width='380' height='300'></iframe>")

        start = new Date()

    }

    function getRandomInt (min, max) {
        return Math.floor(Math.random() * (max - min + 1)) + min;
    }

    function gameOver(score){
        $("#boardGame").html("<h2>You scored "+score+" points</h2><table class='calculatrice' id='calc'><tbody><tr><td class='calc_td_btn'><input type='button' onclick='getHome()' class='stres' value='Restart'></td></tr></tbody></table")
    }

</script>




</body>
</html>

如果你在那里,要小心“ZVOwOzL9uDQ”,“塑料流浪汉”:“BiVXU2jt1Xo”,“死亡斜坡”:“P7cijngnxujm”,“不要坐下,因为我移动了你的椅子”:“h1vybhhqye”,“R U Mine?”:“VQH8ZTgna3Q”,“2013”:“O4kzuc4vpa”,“面包店”:“P_d1eqa2l4”,“魔药逼近”:“Urw780t52zc”,“仍然带你回家”:“FKPKSK1nCKY”,“春丽的旋转鸟踢”:“4lOdBxVS16o”,“走到一起”:“a-5tTz8flYI”,“振作起来”:“PHORT2FNME”,“吸烟者菲奥娜”:“Wg89x455WK4”,“你为什么只有在兴奋的时候才给我打电话?”:“6366dxFf Os”,“砖头接砖头”:“qOTRx3ZqjjI”,“诱惑像你顽皮的朋友一样迎接你”:维诺兹GNMQ0,“金发碧眼的微光陷阱”:“EyBrLYN2Yok”,“坏东西”:“3xTHjLf ONg”,“我自己的特技”:“Er3r_J-mwII”,“爱是激光任务”:“wxQVpRSxOZ0”,“跳舞小骗子”:“hf-B3Y3B0TQ”,“Mardy Bum”:“Lp1fQ51YZMM”,“粘在地板上”:“AQVMJkZGpSc”,“只有知道的人”:“m-seRFY7-cw”,“哭泣的闪电”:“fLsBJPlGIDU”从丽兹酒店到瓦砾堆:“givRh52Ic3A”,“I.D.S.T.”:“V6YORYILYU”,“她是雷雨”,“tvHz5Rti0cU”,“弹射器”,“U3LsJMLWN2k”,“停止这个世界,我想和你一起下车”,“3Yoxmsehyi”,“地狱猫闪闪发光的沙拉拉”:“DalxC19hme”,“我想知道吗?”:“bpOSxM0rNPM”,“膝盖袜”,“00bk5E7gecI”,“这就是你错的地方”:tLOUVbemjro,“在灯亮之前离开”:“SEukS2YN9B8”,“我想要一切”:“SDTxuAEPfdY”,“秘密门”:“ibyGhbvo94Q”,“吮吸它看看”:“rjFGapDkSM0”,“7”:“R2t6vgC_OWw”,“Brianstorm”:“30w8DyEJ_u0”,“宝贝我是你的”:“EDLhMf6voq8”,“Arabella”:“Nj8r3qmOoZ8”,“老黄砖”:“xLaeOrDmWQ4”,“别忘了你是谁的腿”:”qL0Z3Ly0CEw,“防暴车”:“j052 ROwPFM”,“如果你第一次是对的呢?”:“t2cFvzmqmwc”,“火与砰砰”,“我想成为你的”:“Y4NGoS330HE”,“疯狂的声音”:“J_u-FwyoeV3E”,“炉边”:“PG8yTUeptFU”,“下午的帽子”:“qbNKclt42Xc”,“鲁莽小夜曲”:“PY2FQ LgmYo”,“无巴士”:“WK4wISbGvJw”,“电力”:g-cukZ10j8A,“小幻觉机器(维拉尔·里德尔)”:“WLMZUZU8U4”,“Piledriver华尔兹”:“njirT4N JxU”,“日落时”:“EqkBRVukQmE”,“第一党歌”:“83hFiC siDs”,“邪恶孪生兄弟”:“xwir-pg7WiA”,“这房子是马戏团”:“oDB MGsWzQQ”,“我还没有得到我的怪胎”:“a9yrz_psfLc”,“黑糖浆”:“1wznj4lD1Bs”,“505”:ifZfUVp2chE,“危险的动物”:“qHe3E366_Po”,“也许吸血鬼有点强壮,但是……”“SjzOUf0AEiQ”,“荧光青少年”:“ma9I9VBKPiw”,“图书馆图片”:“bmVerkoFPJU”,“下午的风景”:“PeQAZsyucbQ”,“候机室的绝望”:“ZLS8ffCYN80”,“我打赌你在舞池里看起来不错”:“pK7egZaT3hs”大男孩和偷来的情人“:“rLkikLrImnk”,“Balaclava:“6LBCqG0YnTM”,“旧金山的假故事“:“ePg1tbia9Bg”,“D代表危险“:“zOlhvxPC3MQ”,“把你的公爵举起来,John:“O8Wuv1WKldk”,“我的螺旋桨“:“Z5vzov8cpk”,“红色右手“:“hcvgougudgxc”,“一条路“:“qN7gSMPQFss”,“加入点“:“wkvUl\uL3o1c”红灯表示门已经关好了:“hdmR58BIHOg”,“你和我”,“9zXkAaoBOLU”,“Teddy Picker”,“2A2XBoxtcUA”,“平局”,“IQ7NH2jcAAw”,“坏女人”,“YnkJHU3qYIA”,“基石”,“Liqz6ZZZI7R0”,“惊恐餐厅”,“qrqtD4TiO5c”,“某种浪漫”,“WGyj5JyA5Ms”,“如果你发现这一切可能太晚了”,“SqKl1vcmvOU”,“Sqql1vcmvou”“北极猴子是谁?”:“oFeuKVkau6U”,“帮我个忙”:“LXjedllep4”,“你可能看不见灯光,但你一直盯着我看”:“j8iV3tK717s”,“舞鞋”:“3Qelo7TXII”,“珠宝商的手”:“1rq0Ag15sAI”,“斗牛士/Da Frame 2R”:“DxoPxvJ0FNM”,“美丽的访客”:“4n7iaY22Do0”,“你太黑了”:6eoAwXkI3RA“}
风险值得分=0
var nb=0
var iter=0
吴松
var启动
变量点击
var listshongs=[]
回家
$(文档).on(“单击“,”.calc_btn',函数(){
iter++
$(“#valueIter”).html(iter+”/10)
如果(iter==10)
{
游戏结束(分数)
}
其他的
{
单击=新日期()
时间=(单击.getTime()-start.getTime())/1000
if($(this).val()==歌曲){

如果(time哦,我想我看到问题了。你不需要使用.html函数

<div id="boardGame">
</div>

<script type="text/javascript">

    json_dic = {"Too Much to Ask": "oHRjgi6sniY", "Sketchead": "GEfpkuCPjXs", "If You Were There, Beware": "ZVOwOzL9uDQ", "Plastic Tramp": "BiVXU2jt1Xo", "The Death Ramps": "p7cijGnXUJM", "Don't Sit Down 'Cause I've Moved Your Chair": "h1vYbHHhqYE", "R U Mine?": "VQH8ZTgna3Q", "2013": "O4vkZUC4VPA", "The Bakery": "P_D1Eqa2Lk4", "Potion Approaching": "Urw780t52zc", "Still Take You Home": "FKPKSK1nCKY", "Chun-Li's Spinning Bird Kick": "4lOdBxVS16o", "Come Together": "a-5tTz8flYI", "Snap Out of It": "PHoSRT2fNME", "Cigarette Smoker Fiona": "Wg89x455WK4", "Why'd You Only Call Me When You're High?": "6366dxFf-Os", "Brick by Brick": "qOTRx3ZqjjI", "Temptation Greets You Like Your Naughty Friend ": "VEWNOzgnmq0", "The Blond-O-Sonic Shimmer Trap": "EyBrLYN2Yok", "The Bad Thing": "3xTHjLf-ONg", "All My Own Stunts": "Er3r_J-mwII", "Love Is a Laserquest": "wxQVpRSxOZ0", "Dance Little Liar": "hf-B3Y3B0TQ", "Mardy Bum": "Lp1fQ51YZMM", "Stickin' to the Floor": "AQVMJkZGpSc", "Only Ones Who Know": "m-seRFY7-cw", "Crying Lightning": "fLsBJPlGIDU", "From the Ritz to the Rubble ": "givRh52Ic3A", "I.D.S.T.": "V6yORYEiLyU", "She's Thunderstorms": "tvHz5Rti0cU", "Catapult": "U3LsJMLWN2k", "Stop the World I Wanna Get Off with You": "3PyoxMSEHYI", "The Hellcat Spangled Shalalala": "dAlRXC19hmE", "Do I Wanna Know?": "bpOSxM0rNPM", "Knee Socks": "00bk5E7gecI", "That's Where You're Wrong": "tLOUVbemjro", "Leave Before the Lights Come On": "SEukS2YN9B8", "I Want It All": "SDTxuAEPfdY", "Secret Door": "ibyGhbvo94Q", "Suck It and See": "rjFGapDkSM0", "7": "R2t6vgC_OWw", "Brianstorm": "30w8DyEJ__0", "Baby I'm Yours": "EDLhMf6voq8", "Arabella": "Nj8r3qmOoZ8", "Old Yellow Bricks": "xLaeOrDmWQ4", "Don't Forget Whose Legs You're On": "qL0Z3Ly0CEw", "Riot Van": "j052-ROwPFM", "What If You Were Right the First Time?": "t2cFvzmqmwc", "Fire and the Thud": "VGlhSSP4nTk", "I Wanna Be Yours": "Y4NGoS330HE", "Mad Sounds": "J_-FwyoeV3E", "Fireside": "PG8yTUeptFU", "The Afternoon's Hat": "qbNKclt42Xc", "Reckless Serenade": "PY2FQ-LgmYo", "No Buses": "WK4wISbGvJw", "Electricity": "g-cukZ10j8A", "Little Illusion Machine (Wirral Riddler) ": "WlMzuzud8U4", "Piledriver Waltz": "njirT4N-JxU", "When the Sun Goes Down": "EqkBRVukQmE", "No. 1 Party Anthem": "83hFiC-siDs", "Evil Twin": "xwir-pg7WiA", "This House Is a Circus": "oDB-MGsWzQQ", "I Haven't Got My Strange": "a9yrz_psfLc", "Black Treacle": "1wznj4lD1Bs", "505": "ifZfUVp2chE", "Dangerous Animals": "qHe3E366_Po", "Perhaps Vampires Is a Bit Strong But..": "SjzOUf0AEiQ", "Fluorescent Adolescent": "ma9I9VBKPiw", "Library Pictures": "bmVerkoFPJU", "The View from the Afternoon": "PeQAZsyucbQ", "Despair in the Departure Lounge": "ZLS8ffCYN80", "I Bet You Look Good on the Dancefloor": "pK7egZaT3hs", "Bigger Boys and Stolen Sweethearts": "rLkikLrImnk", "Balaclava": "6LBCqG0YnTM", "Fake Tales of San Francisco": "ePg1tbia9Bg", "D Is for Dangerous": "zOlhvxPC3MQ", "Put Your Dukes Up John": "O8Wuv1WKldk", "My Propeller": "Z5vZovv8cPk", "Red Right Hand": "hcvGOUuDGXc", "One for the Road": "qN7gSMPQFss", "Joining the Dots": "wkvUl_l3o1c", "Red Light Indicates Doors Are Secured": "hdmR58BIHOg", "You and I ": "9zXkAaoBOLU", "Teddy Picker": "2A2XBoxtcUA", "Settle for a Draw": "IQ7NH2jcAAw", "Bad Woman ": "YnkJHU3qYIA", "Cornerstone": "LIQz6zZi7R0", "Fright Lined Dining Room": "qrqtD4TiO5c", "A Certain Romance": "WGyj5JyA5Ms", "If You Found This It's Probably Too Late": "SqKl1vcmvOU", "Who the Fuck Are Arctic Monkeys?": "oFeuKVkau6U", "Do Me a Favour": "lXJEDlLepD4", "You Probably Couldn't See for the Lights but You Were Staring Straight at Me": "j8iV3tK717s", "Dancing Shoes": "3aQELo7tXyI", "The Jeweller's Hands": "1rq0Ag15sAI", "Matador/Da Frame 2R": "DxoPxvJ0FNM", "Pretty Visitors": "4n7iaY22Do0", "You're So Dark": "6eoAwXkI3RA"}

    var score = 0
    var nb = 0
    var iter = 0
    var song
    var start
    var click
    var listSongs = []

    getHome()

    $(document).on("click", '.calc_btn', function() {

        iter++
        $("#valueIter").html(iter+"/10")
        if(iter == 10)
        {
            gameOver(score)
        }
        else 
        {
            click = new Date()
            time = (click.getTime() - start.getTime())/1000
            if($(this).val() == song){
                if(time <= 15)
                    score += parseInt((-1000/14)*time+929)
                $("#valueScore").html(score)
                $("#valueScore").css( "color", "green" )
            } 
            else
            {
                $("#valueScore").html(score)
                $("#valueScore").css( "color", "red" )
            }
            nb += 1
            getSong()
        }
    })

    function getHome()
    {
        score = 0
        iter = 0
        listSongs = []
        $("#boardGame").html("<h2>Welcome to The Game of Monkeys</h2><table class='calculatrice' id='calc'><tbody><tr><td class='calc_td_btn'><input type='button' class='stres' value='Start' onclick='getSong()'></td></tr></tbody></table")
    }

    function getSong()
    {
        var keys = [];
        for (var prop in json_dic) {
            if (json_dic.hasOwnProperty(prop)) {
                keys.push(prop);
            }
        }

        song = keys[ keys.length * Math.random() << 0 ];
        listSongs = [ song ]
        url = json_dic[song]

        while(listSongs.length <= 4)
        {
            var keys = [];
            for (var prop in json_dic) {
                if (json_dic.hasOwnProperty(prop)) {
                    keys.push(prop);
                }
            }

            song_random = keys[ keys.length * Math.random() << 0 ];
            listSongs.push(song_random)
        }

        $("#boardGame").html('<table class="calculatrice" id="calc"> '+
            '<tbody>' +
            '<tr>' +
            '<td class="calc_td_btn">' +
            '<div style="position:relative;width:380px;height:25px;overflow:hidden;">' +
            '<div id="yt_video" style="position:absolute;top:-276px;left:-5px">' +
            '</div>' +
            '</div>' +
            '</td>' +
            '</tr>');

        for(var i = 0; i <= 4; i++)
        {
            var randomIndex = Math.floor(Math.random() * listSongs.length);
            var randomString = listSongs[randomIndex];
            $("#boardGame").append('<tr>'+
                '<td class="calc_td_btn">' +
                '<input type="button" class="calc_btn" value="'+randomString+'">' +
                '</td>' +
                '</tr>')
            var index = listSongs.indexOf(randomString);
            listSongs.splice(index, 1);
        }

        $("#boardGame").append('<tr>' +
            '<td class="calc_td_btn">' +
            '<h2 id="valueScore">0 points</h2>' +
            '<h2 id="valueIter">0/10</h2>' +
            '<input type="button" class="stres" onclick="getHome()" value="Restart">' +
            '</td>' +
            '</tr>' +
            '</tbody>' +
            '</table>')

        var nb = getRandomInt(0,100)
        $("#yt_video").html("<iframe src='https://www.youtube.com/embed/"+url+"?autoplay=0&start="+nb+"' id='yt_video' width='380' height='300'></iframe>")

        start = new Date()

    }

    function getRandomInt (min, max) {
        return Math.floor(Math.random() * (max - min + 1)) + min;
    }

    function gameOver(score){
        $("#boardGame").html("<h2>You scored "+score+" points</h2><table class='calculatrice' id='calc'><tbody><tr><td class='calc_td_btn'><input type='button' onclick='getHome()' class='stres' value='Restart'></td></tr></tbody></table")
    }

</script>




</body>
</html>
使用jQuery:

<div id="boardGame">
</div>

<script type="text/javascript">

    json_dic = {"Too Much to Ask": "oHRjgi6sniY", "Sketchead": "GEfpkuCPjXs", "If You Were There, Beware": "ZVOwOzL9uDQ", "Plastic Tramp": "BiVXU2jt1Xo", "The Death Ramps": "p7cijGnXUJM", "Don't Sit Down 'Cause I've Moved Your Chair": "h1vYbHHhqYE", "R U Mine?": "VQH8ZTgna3Q", "2013": "O4vkZUC4VPA", "The Bakery": "P_D1Eqa2Lk4", "Potion Approaching": "Urw780t52zc", "Still Take You Home": "FKPKSK1nCKY", "Chun-Li's Spinning Bird Kick": "4lOdBxVS16o", "Come Together": "a-5tTz8flYI", "Snap Out of It": "PHoSRT2fNME", "Cigarette Smoker Fiona": "Wg89x455WK4", "Why'd You Only Call Me When You're High?": "6366dxFf-Os", "Brick by Brick": "qOTRx3ZqjjI", "Temptation Greets You Like Your Naughty Friend ": "VEWNOzgnmq0", "The Blond-O-Sonic Shimmer Trap": "EyBrLYN2Yok", "The Bad Thing": "3xTHjLf-ONg", "All My Own Stunts": "Er3r_J-mwII", "Love Is a Laserquest": "wxQVpRSxOZ0", "Dance Little Liar": "hf-B3Y3B0TQ", "Mardy Bum": "Lp1fQ51YZMM", "Stickin' to the Floor": "AQVMJkZGpSc", "Only Ones Who Know": "m-seRFY7-cw", "Crying Lightning": "fLsBJPlGIDU", "From the Ritz to the Rubble ": "givRh52Ic3A", "I.D.S.T.": "V6yORYEiLyU", "She's Thunderstorms": "tvHz5Rti0cU", "Catapult": "U3LsJMLWN2k", "Stop the World I Wanna Get Off with You": "3PyoxMSEHYI", "The Hellcat Spangled Shalalala": "dAlRXC19hmE", "Do I Wanna Know?": "bpOSxM0rNPM", "Knee Socks": "00bk5E7gecI", "That's Where You're Wrong": "tLOUVbemjro", "Leave Before the Lights Come On": "SEukS2YN9B8", "I Want It All": "SDTxuAEPfdY", "Secret Door": "ibyGhbvo94Q", "Suck It and See": "rjFGapDkSM0", "7": "R2t6vgC_OWw", "Brianstorm": "30w8DyEJ__0", "Baby I'm Yours": "EDLhMf6voq8", "Arabella": "Nj8r3qmOoZ8", "Old Yellow Bricks": "xLaeOrDmWQ4", "Don't Forget Whose Legs You're On": "qL0Z3Ly0CEw", "Riot Van": "j052-ROwPFM", "What If You Were Right the First Time?": "t2cFvzmqmwc", "Fire and the Thud": "VGlhSSP4nTk", "I Wanna Be Yours": "Y4NGoS330HE", "Mad Sounds": "J_-FwyoeV3E", "Fireside": "PG8yTUeptFU", "The Afternoon's Hat": "qbNKclt42Xc", "Reckless Serenade": "PY2FQ-LgmYo", "No Buses": "WK4wISbGvJw", "Electricity": "g-cukZ10j8A", "Little Illusion Machine (Wirral Riddler) ": "WlMzuzud8U4", "Piledriver Waltz": "njirT4N-JxU", "When the Sun Goes Down": "EqkBRVukQmE", "No. 1 Party Anthem": "83hFiC-siDs", "Evil Twin": "xwir-pg7WiA", "This House Is a Circus": "oDB-MGsWzQQ", "I Haven't Got My Strange": "a9yrz_psfLc", "Black Treacle": "1wznj4lD1Bs", "505": "ifZfUVp2chE", "Dangerous Animals": "qHe3E366_Po", "Perhaps Vampires Is a Bit Strong But..": "SjzOUf0AEiQ", "Fluorescent Adolescent": "ma9I9VBKPiw", "Library Pictures": "bmVerkoFPJU", "The View from the Afternoon": "PeQAZsyucbQ", "Despair in the Departure Lounge": "ZLS8ffCYN80", "I Bet You Look Good on the Dancefloor": "pK7egZaT3hs", "Bigger Boys and Stolen Sweethearts": "rLkikLrImnk", "Balaclava": "6LBCqG0YnTM", "Fake Tales of San Francisco": "ePg1tbia9Bg", "D Is for Dangerous": "zOlhvxPC3MQ", "Put Your Dukes Up John": "O8Wuv1WKldk", "My Propeller": "Z5vZovv8cPk", "Red Right Hand": "hcvGOUuDGXc", "One for the Road": "qN7gSMPQFss", "Joining the Dots": "wkvUl_l3o1c", "Red Light Indicates Doors Are Secured": "hdmR58BIHOg", "You and I ": "9zXkAaoBOLU", "Teddy Picker": "2A2XBoxtcUA", "Settle for a Draw": "IQ7NH2jcAAw", "Bad Woman ": "YnkJHU3qYIA", "Cornerstone": "LIQz6zZi7R0", "Fright Lined Dining Room": "qrqtD4TiO5c", "A Certain Romance": "WGyj5JyA5Ms", "If You Found This It's Probably Too Late": "SqKl1vcmvOU", "Who the Fuck Are Arctic Monkeys?": "oFeuKVkau6U", "Do Me a Favour": "lXJEDlLepD4", "You Probably Couldn't See for the Lights but You Were Staring Straight at Me": "j8iV3tK717s", "Dancing Shoes": "3aQELo7tXyI", "The Jeweller's Hands": "1rq0Ag15sAI", "Matador/Da Frame 2R": "DxoPxvJ0FNM", "Pretty Visitors": "4n7iaY22Do0", "You're So Dark": "6eoAwXkI3RA"}

    var score = 0
    var nb = 0
    var iter = 0
    var song
    var start
    var click
    var listSongs = []

    getHome()

    $(document).on("click", '.calc_btn', function() {

        iter++
        $("#valueIter").html(iter+"/10")
        if(iter == 10)
        {
            gameOver(score)
        }
        else 
        {
            click = new Date()
            time = (click.getTime() - start.getTime())/1000
            if($(this).val() == song){
                if(time <= 15)
                    score += parseInt((-1000/14)*time+929)
                $("#valueScore").html(score)
                $("#valueScore").css( "color", "green" )
            } 
            else
            {
                $("#valueScore").html(score)
                $("#valueScore").css( "color", "red" )
            }
            nb += 1
            getSong()
        }
    })

    function getHome()
    {
        score = 0
        iter = 0
        listSongs = []
        $("#boardGame").html("<h2>Welcome to The Game of Monkeys</h2><table class='calculatrice' id='calc'><tbody><tr><td class='calc_td_btn'><input type='button' class='stres' value='Start' onclick='getSong()'></td></tr></tbody></table")
    }

    function getSong()
    {
        var keys = [];
        for (var prop in json_dic) {
            if (json_dic.hasOwnProperty(prop)) {
                keys.push(prop);
            }
        }

        song = keys[ keys.length * Math.random() << 0 ];
        listSongs = [ song ]
        url = json_dic[song]

        while(listSongs.length <= 4)
        {
            var keys = [];
            for (var prop in json_dic) {
                if (json_dic.hasOwnProperty(prop)) {
                    keys.push(prop);
                }
            }

            song_random = keys[ keys.length * Math.random() << 0 ];
            listSongs.push(song_random)
        }

        $("#boardGame").html('<table class="calculatrice" id="calc"> '+
            '<tbody>' +
            '<tr>' +
            '<td class="calc_td_btn">' +
            '<div style="position:relative;width:380px;height:25px;overflow:hidden;">' +
            '<div id="yt_video" style="position:absolute;top:-276px;left:-5px">' +
            '</div>' +
            '</div>' +
            '</td>' +
            '</tr>');

        for(var i = 0; i <= 4; i++)
        {
            var randomIndex = Math.floor(Math.random() * listSongs.length);
            var randomString = listSongs[randomIndex];
            $("#boardGame").append('<tr>'+
                '<td class="calc_td_btn">' +
                '<input type="button" class="calc_btn" value="'+randomString+'">' +
                '</td>' +
                '</tr>')
            var index = listSongs.indexOf(randomString);
            listSongs.splice(index, 1);
        }

        $("#boardGame").append('<tr>' +
            '<td class="calc_td_btn">' +
            '<h2 id="valueScore">0 points</h2>' +
            '<h2 id="valueIter">0/10</h2>' +
            '<input type="button" class="stres" onclick="getHome()" value="Restart">' +
            '</td>' +
            '</tr>' +
            '</tbody>' +
            '</table>')

        var nb = getRandomInt(0,100)
        $("#yt_video").html("<iframe src='https://www.youtube.com/embed/"+url+"?autoplay=0&start="+nb+"' id='yt_video' width='380' height='300'></iframe>")

        start = new Date()

    }

    function getRandomInt (min, max) {
        return Math.floor(Math.random() * (max - min + 1)) + min;
    }

    function gameOver(score){
        $("#boardGame").html("<h2>You scored "+score+" points</h2><table class='calculatrice' id='calc'><tbody><tr><td class='calc_td_btn'><input type='button' onclick='getHome()' class='stres' value='Restart'></td></tr></tbody></table")
    }

</script>




</body>
</html>
$("#valueIter").val(iter+"/10");
$("#valueScore").val(score);
html函数用于用原始html填充元素。这里的区别是,jQuery提供.val()和.text()作为任何元素的getter和setter,这些元素等同于

<div id="boardGame">
</div>

<script type="text/javascript">

    json_dic = {"Too Much to Ask": "oHRjgi6sniY", "Sketchead": "GEfpkuCPjXs", "If You Were There, Beware": "ZVOwOzL9uDQ", "Plastic Tramp": "BiVXU2jt1Xo", "The Death Ramps": "p7cijGnXUJM", "Don't Sit Down 'Cause I've Moved Your Chair": "h1vYbHHhqYE", "R U Mine?": "VQH8ZTgna3Q", "2013": "O4vkZUC4VPA", "The Bakery": "P_D1Eqa2Lk4", "Potion Approaching": "Urw780t52zc", "Still Take You Home": "FKPKSK1nCKY", "Chun-Li's Spinning Bird Kick": "4lOdBxVS16o", "Come Together": "a-5tTz8flYI", "Snap Out of It": "PHoSRT2fNME", "Cigarette Smoker Fiona": "Wg89x455WK4", "Why'd You Only Call Me When You're High?": "6366dxFf-Os", "Brick by Brick": "qOTRx3ZqjjI", "Temptation Greets You Like Your Naughty Friend ": "VEWNOzgnmq0", "The Blond-O-Sonic Shimmer Trap": "EyBrLYN2Yok", "The Bad Thing": "3xTHjLf-ONg", "All My Own Stunts": "Er3r_J-mwII", "Love Is a Laserquest": "wxQVpRSxOZ0", "Dance Little Liar": "hf-B3Y3B0TQ", "Mardy Bum": "Lp1fQ51YZMM", "Stickin' to the Floor": "AQVMJkZGpSc", "Only Ones Who Know": "m-seRFY7-cw", "Crying Lightning": "fLsBJPlGIDU", "From the Ritz to the Rubble ": "givRh52Ic3A", "I.D.S.T.": "V6yORYEiLyU", "She's Thunderstorms": "tvHz5Rti0cU", "Catapult": "U3LsJMLWN2k", "Stop the World I Wanna Get Off with You": "3PyoxMSEHYI", "The Hellcat Spangled Shalalala": "dAlRXC19hmE", "Do I Wanna Know?": "bpOSxM0rNPM", "Knee Socks": "00bk5E7gecI", "That's Where You're Wrong": "tLOUVbemjro", "Leave Before the Lights Come On": "SEukS2YN9B8", "I Want It All": "SDTxuAEPfdY", "Secret Door": "ibyGhbvo94Q", "Suck It and See": "rjFGapDkSM0", "7": "R2t6vgC_OWw", "Brianstorm": "30w8DyEJ__0", "Baby I'm Yours": "EDLhMf6voq8", "Arabella": "Nj8r3qmOoZ8", "Old Yellow Bricks": "xLaeOrDmWQ4", "Don't Forget Whose Legs You're On": "qL0Z3Ly0CEw", "Riot Van": "j052-ROwPFM", "What If You Were Right the First Time?": "t2cFvzmqmwc", "Fire and the Thud": "VGlhSSP4nTk", "I Wanna Be Yours": "Y4NGoS330HE", "Mad Sounds": "J_-FwyoeV3E", "Fireside": "PG8yTUeptFU", "The Afternoon's Hat": "qbNKclt42Xc", "Reckless Serenade": "PY2FQ-LgmYo", "No Buses": "WK4wISbGvJw", "Electricity": "g-cukZ10j8A", "Little Illusion Machine (Wirral Riddler) ": "WlMzuzud8U4", "Piledriver Waltz": "njirT4N-JxU", "When the Sun Goes Down": "EqkBRVukQmE", "No. 1 Party Anthem": "83hFiC-siDs", "Evil Twin": "xwir-pg7WiA", "This House Is a Circus": "oDB-MGsWzQQ", "I Haven't Got My Strange": "a9yrz_psfLc", "Black Treacle": "1wznj4lD1Bs", "505": "ifZfUVp2chE", "Dangerous Animals": "qHe3E366_Po", "Perhaps Vampires Is a Bit Strong But..": "SjzOUf0AEiQ", "Fluorescent Adolescent": "ma9I9VBKPiw", "Library Pictures": "bmVerkoFPJU", "The View from the Afternoon": "PeQAZsyucbQ", "Despair in the Departure Lounge": "ZLS8ffCYN80", "I Bet You Look Good on the Dancefloor": "pK7egZaT3hs", "Bigger Boys and Stolen Sweethearts": "rLkikLrImnk", "Balaclava": "6LBCqG0YnTM", "Fake Tales of San Francisco": "ePg1tbia9Bg", "D Is for Dangerous": "zOlhvxPC3MQ", "Put Your Dukes Up John": "O8Wuv1WKldk", "My Propeller": "Z5vZovv8cPk", "Red Right Hand": "hcvGOUuDGXc", "One for the Road": "qN7gSMPQFss", "Joining the Dots": "wkvUl_l3o1c", "Red Light Indicates Doors Are Secured": "hdmR58BIHOg", "You and I ": "9zXkAaoBOLU", "Teddy Picker": "2A2XBoxtcUA", "Settle for a Draw": "IQ7NH2jcAAw", "Bad Woman ": "YnkJHU3qYIA", "Cornerstone": "LIQz6zZi7R0", "Fright Lined Dining Room": "qrqtD4TiO5c", "A Certain Romance": "WGyj5JyA5Ms", "If You Found This It's Probably Too Late": "SqKl1vcmvOU", "Who the Fuck Are Arctic Monkeys?": "oFeuKVkau6U", "Do Me a Favour": "lXJEDlLepD4", "You Probably Couldn't See for the Lights but You Were Staring Straight at Me": "j8iV3tK717s", "Dancing Shoes": "3aQELo7tXyI", "The Jeweller's Hands": "1rq0Ag15sAI", "Matador/Da Frame 2R": "DxoPxvJ0FNM", "Pretty Visitors": "4n7iaY22Do0", "You're So Dark": "6eoAwXkI3RA"}

    var score = 0
    var nb = 0
    var iter = 0
    var song
    var start
    var click
    var listSongs = []

    getHome()

    $(document).on("click", '.calc_btn', function() {

        iter++
        $("#valueIter").html(iter+"/10")
        if(iter == 10)
        {
            gameOver(score)
        }
        else 
        {
            click = new Date()
            time = (click.getTime() - start.getTime())/1000
            if($(this).val() == song){
                if(time <= 15)
                    score += parseInt((-1000/14)*time+929)
                $("#valueScore").html(score)
                $("#valueScore").css( "color", "green" )
            } 
            else
            {
                $("#valueScore").html(score)
                $("#valueScore").css( "color", "red" )
            }
            nb += 1
            getSong()
        }
    })

    function getHome()
    {
        score = 0
        iter = 0
        listSongs = []
        $("#boardGame").html("<h2>Welcome to The Game of Monkeys</h2><table class='calculatrice' id='calc'><tbody><tr><td class='calc_td_btn'><input type='button' class='stres' value='Start' onclick='getSong()'></td></tr></tbody></table")
    }

    function getSong()
    {
        var keys = [];
        for (var prop in json_dic) {
            if (json_dic.hasOwnProperty(prop)) {
                keys.push(prop);
            }
        }

        song = keys[ keys.length * Math.random() << 0 ];
        listSongs = [ song ]
        url = json_dic[song]

        while(listSongs.length <= 4)
        {
            var keys = [];
            for (var prop in json_dic) {
                if (json_dic.hasOwnProperty(prop)) {
                    keys.push(prop);
                }
            }

            song_random = keys[ keys.length * Math.random() << 0 ];
            listSongs.push(song_random)
        }

        $("#boardGame").html('<table class="calculatrice" id="calc"> '+
            '<tbody>' +
            '<tr>' +
            '<td class="calc_td_btn">' +
            '<div style="position:relative;width:380px;height:25px;overflow:hidden;">' +
            '<div id="yt_video" style="position:absolute;top:-276px;left:-5px">' +
            '</div>' +
            '</div>' +
            '</td>' +
            '</tr>');

        for(var i = 0; i <= 4; i++)
        {
            var randomIndex = Math.floor(Math.random() * listSongs.length);
            var randomString = listSongs[randomIndex];
            $("#boardGame").append('<tr>'+
                '<td class="calc_td_btn">' +
                '<input type="button" class="calc_btn" value="'+randomString+'">' +
                '</td>' +
                '</tr>')
            var index = listSongs.indexOf(randomString);
            listSongs.splice(index, 1);
        }

        $("#boardGame").append('<tr>' +
            '<td class="calc_td_btn">' +
            '<h2 id="valueScore">0 points</h2>' +
            '<h2 id="valueIter">0/10</h2>' +
            '<input type="button" class="stres" onclick="getHome()" value="Restart">' +
            '</td>' +
            '</tr>' +
            '</tbody>' +
            '</table>')

        var nb = getRandomInt(0,100)
        $("#yt_video").html("<iframe src='https://www.youtube.com/embed/"+url+"?autoplay=0&start="+nb+"' id='yt_video' width='380' height='300'></iframe>")

        start = new Date()

    }

    function getRandomInt (min, max) {
        return Math.floor(Math.random() * (max - min + 1)) + min;
    }

    function gameOver(score){
        $("#boardGame").html("<h2>You scored "+score+" points</h2><table class='calculatrice' id='calc'><tbody><tr><td class='calc_td_btn'><input type='button' onclick='getHome()' class='stres' value='Restart'></td></tr></tbody></table")
    }

</script>




</body>
</html>
element.value = score;

问题是,您正在吹走第93-106行中所有元素的DOM,并且正在创建它们。因此,您正在设置分数的元素正在被销毁并替换为完全不同的

<div id="boardGame">
</div>

<script type="text/javascript">

    json_dic = {"Too Much to Ask": "oHRjgi6sniY", "Sketchead": "GEfpkuCPjXs", "If You Were There, Beware": "ZVOwOzL9uDQ", "Plastic Tramp": "BiVXU2jt1Xo", "The Death Ramps": "p7cijGnXUJM", "Don't Sit Down 'Cause I've Moved Your Chair": "h1vYbHHhqYE", "R U Mine?": "VQH8ZTgna3Q", "2013": "O4vkZUC4VPA", "The Bakery": "P_D1Eqa2Lk4", "Potion Approaching": "Urw780t52zc", "Still Take You Home": "FKPKSK1nCKY", "Chun-Li's Spinning Bird Kick": "4lOdBxVS16o", "Come Together": "a-5tTz8flYI", "Snap Out of It": "PHoSRT2fNME", "Cigarette Smoker Fiona": "Wg89x455WK4", "Why'd You Only Call Me When You're High?": "6366dxFf-Os", "Brick by Brick": "qOTRx3ZqjjI", "Temptation Greets You Like Your Naughty Friend ": "VEWNOzgnmq0", "The Blond-O-Sonic Shimmer Trap": "EyBrLYN2Yok", "The Bad Thing": "3xTHjLf-ONg", "All My Own Stunts": "Er3r_J-mwII", "Love Is a Laserquest": "wxQVpRSxOZ0", "Dance Little Liar": "hf-B3Y3B0TQ", "Mardy Bum": "Lp1fQ51YZMM", "Stickin' to the Floor": "AQVMJkZGpSc", "Only Ones Who Know": "m-seRFY7-cw", "Crying Lightning": "fLsBJPlGIDU", "From the Ritz to the Rubble ": "givRh52Ic3A", "I.D.S.T.": "V6yORYEiLyU", "She's Thunderstorms": "tvHz5Rti0cU", "Catapult": "U3LsJMLWN2k", "Stop the World I Wanna Get Off with You": "3PyoxMSEHYI", "The Hellcat Spangled Shalalala": "dAlRXC19hmE", "Do I Wanna Know?": "bpOSxM0rNPM", "Knee Socks": "00bk5E7gecI", "That's Where You're Wrong": "tLOUVbemjro", "Leave Before the Lights Come On": "SEukS2YN9B8", "I Want It All": "SDTxuAEPfdY", "Secret Door": "ibyGhbvo94Q", "Suck It and See": "rjFGapDkSM0", "7": "R2t6vgC_OWw", "Brianstorm": "30w8DyEJ__0", "Baby I'm Yours": "EDLhMf6voq8", "Arabella": "Nj8r3qmOoZ8", "Old Yellow Bricks": "xLaeOrDmWQ4", "Don't Forget Whose Legs You're On": "qL0Z3Ly0CEw", "Riot Van": "j052-ROwPFM", "What If You Were Right the First Time?": "t2cFvzmqmwc", "Fire and the Thud": "VGlhSSP4nTk", "I Wanna Be Yours": "Y4NGoS330HE", "Mad Sounds": "J_-FwyoeV3E", "Fireside": "PG8yTUeptFU", "The Afternoon's Hat": "qbNKclt42Xc", "Reckless Serenade": "PY2FQ-LgmYo", "No Buses": "WK4wISbGvJw", "Electricity": "g-cukZ10j8A", "Little Illusion Machine (Wirral Riddler) ": "WlMzuzud8U4", "Piledriver Waltz": "njirT4N-JxU", "When the Sun Goes Down": "EqkBRVukQmE", "No. 1 Party Anthem": "83hFiC-siDs", "Evil Twin": "xwir-pg7WiA", "This House Is a Circus": "oDB-MGsWzQQ", "I Haven't Got My Strange": "a9yrz_psfLc", "Black Treacle": "1wznj4lD1Bs", "505": "ifZfUVp2chE", "Dangerous Animals": "qHe3E366_Po", "Perhaps Vampires Is a Bit Strong But..": "SjzOUf0AEiQ", "Fluorescent Adolescent": "ma9I9VBKPiw", "Library Pictures": "bmVerkoFPJU", "The View from the Afternoon": "PeQAZsyucbQ", "Despair in the Departure Lounge": "ZLS8ffCYN80", "I Bet You Look Good on the Dancefloor": "pK7egZaT3hs", "Bigger Boys and Stolen Sweethearts": "rLkikLrImnk", "Balaclava": "6LBCqG0YnTM", "Fake Tales of San Francisco": "ePg1tbia9Bg", "D Is for Dangerous": "zOlhvxPC3MQ", "Put Your Dukes Up John": "O8Wuv1WKldk", "My Propeller": "Z5vZovv8cPk", "Red Right Hand": "hcvGOUuDGXc", "One for the Road": "qN7gSMPQFss", "Joining the Dots": "wkvUl_l3o1c", "Red Light Indicates Doors Are Secured": "hdmR58BIHOg", "You and I ": "9zXkAaoBOLU", "Teddy Picker": "2A2XBoxtcUA", "Settle for a Draw": "IQ7NH2jcAAw", "Bad Woman ": "YnkJHU3qYIA", "Cornerstone": "LIQz6zZi7R0", "Fright Lined Dining Room": "qrqtD4TiO5c", "A Certain Romance": "WGyj5JyA5Ms", "If You Found This It's Probably Too Late": "SqKl1vcmvOU", "Who the Fuck Are Arctic Monkeys?": "oFeuKVkau6U", "Do Me a Favour": "lXJEDlLepD4", "You Probably Couldn't See for the Lights but You Were Staring Straight at Me": "j8iV3tK717s", "Dancing Shoes": "3aQELo7tXyI", "The Jeweller's Hands": "1rq0Ag15sAI", "Matador/Da Frame 2R": "DxoPxvJ0FNM", "Pretty Visitors": "4n7iaY22Do0", "You're So Dark": "6eoAwXkI3RA"}

    var score = 0
    var nb = 0
    var iter = 0
    var song
    var start
    var click
    var listSongs = []

    getHome()

    $(document).on("click", '.calc_btn', function() {

        iter++
        $("#valueIter").html(iter+"/10")
        if(iter == 10)
        {
            gameOver(score)
        }
        else 
        {
            click = new Date()
            time = (click.getTime() - start.getTime())/1000
            if($(this).val() == song){
                if(time <= 15)
                    score += parseInt((-1000/14)*time+929)
                $("#valueScore").html(score)
                $("#valueScore").css( "color", "green" )
            } 
            else
            {
                $("#valueScore").html(score)
                $("#valueScore").css( "color", "red" )
            }
            nb += 1
            getSong()
        }
    })

    function getHome()
    {
        score = 0
        iter = 0
        listSongs = []
        $("#boardGame").html("<h2>Welcome to The Game of Monkeys</h2><table class='calculatrice' id='calc'><tbody><tr><td class='calc_td_btn'><input type='button' class='stres' value='Start' onclick='getSong()'></td></tr></tbody></table")
    }

    function getSong()
    {
        var keys = [];
        for (var prop in json_dic) {
            if (json_dic.hasOwnProperty(prop)) {
                keys.push(prop);
            }
        }

        song = keys[ keys.length * Math.random() << 0 ];
        listSongs = [ song ]
        url = json_dic[song]

        while(listSongs.length <= 4)
        {
            var keys = [];
            for (var prop in json_dic) {
                if (json_dic.hasOwnProperty(prop)) {
                    keys.push(prop);
                }
            }

            song_random = keys[ keys.length * Math.random() << 0 ];
            listSongs.push(song_random)
        }

        $("#boardGame").html('<table class="calculatrice" id="calc"> '+
            '<tbody>' +
            '<tr>' +
            '<td class="calc_td_btn">' +
            '<div style="position:relative;width:380px;height:25px;overflow:hidden;">' +
            '<div id="yt_video" style="position:absolute;top:-276px;left:-5px">' +
            '</div>' +
            '</div>' +
            '</td>' +
            '</tr>');

        for(var i = 0; i <= 4; i++)
        {
            var randomIndex = Math.floor(Math.random() * listSongs.length);
            var randomString = listSongs[randomIndex];
            $("#boardGame").append('<tr>'+
                '<td class="calc_td_btn">' +
                '<input type="button" class="calc_btn" value="'+randomString+'">' +
                '</td>' +
                '</tr>')
            var index = listSongs.indexOf(randomString);
            listSongs.splice(index, 1);
        }

        $("#boardGame").append('<tr>' +
            '<td class="calc_td_btn">' +
            '<h2 id="valueScore">0 points</h2>' +
            '<h2 id="valueIter">0/10</h2>' +
            '<input type="button" class="stres" onclick="getHome()" value="Restart">' +
            '</td>' +
            '</tr>' +
            '</tbody>' +
            '</table>')

        var nb = getRandomInt(0,100)
        $("#yt_video").html("<iframe src='https://www.youtube.com/embed/"+url+"?autoplay=0&start="+nb+"' id='yt_video' width='380' height='300'></iframe>")

        start = new Date()

    }

    function getRandomInt (min, max) {
        return Math.floor(Math.random() * (max - min + 1)) + min;
    }

    function gameOver(score){
        $("#boardGame").html("<h2>You scored "+score+" points</h2><table class='calculatrice' id='calc'><tbody><tr><td class='calc_td_btn'><input type='button' onclick='getHome()' class='stres' value='Restart'></td></tr></tbody></table")
    }

</script>




</body>
</html>
您需要使用JQuery来修改已经存在的按钮,为它们提供歌曲列表的名称,而不是销毁所有内容(第82行是替换“#boardGame”的html的地方)

<div id="boardGame">
</div>

<script type="text/javascript">

    json_dic = {"Too Much to Ask": "oHRjgi6sniY", "Sketchead": "GEfpkuCPjXs", "If You Were There, Beware": "ZVOwOzL9uDQ", "Plastic Tramp": "BiVXU2jt1Xo", "The Death Ramps": "p7cijGnXUJM", "Don't Sit Down 'Cause I've Moved Your Chair": "h1vYbHHhqYE", "R U Mine?": "VQH8ZTgna3Q", "2013": "O4vkZUC4VPA", "The Bakery": "P_D1Eqa2Lk4", "Potion Approaching": "Urw780t52zc", "Still Take You Home": "FKPKSK1nCKY", "Chun-Li's Spinning Bird Kick": "4lOdBxVS16o", "Come Together": "a-5tTz8flYI", "Snap Out of It": "PHoSRT2fNME", "Cigarette Smoker Fiona": "Wg89x455WK4", "Why'd You Only Call Me When You're High?": "6366dxFf-Os", "Brick by Brick": "qOTRx3ZqjjI", "Temptation Greets You Like Your Naughty Friend ": "VEWNOzgnmq0", "The Blond-O-Sonic Shimmer Trap": "EyBrLYN2Yok", "The Bad Thing": "3xTHjLf-ONg", "All My Own Stunts": "Er3r_J-mwII", "Love Is a Laserquest": "wxQVpRSxOZ0", "Dance Little Liar": "hf-B3Y3B0TQ", "Mardy Bum": "Lp1fQ51YZMM", "Stickin' to the Floor": "AQVMJkZGpSc", "Only Ones Who Know": "m-seRFY7-cw", "Crying Lightning": "fLsBJPlGIDU", "From the Ritz to the Rubble ": "givRh52Ic3A", "I.D.S.T.": "V6yORYEiLyU", "She's Thunderstorms": "tvHz5Rti0cU", "Catapult": "U3LsJMLWN2k", "Stop the World I Wanna Get Off with You": "3PyoxMSEHYI", "The Hellcat Spangled Shalalala": "dAlRXC19hmE", "Do I Wanna Know?": "bpOSxM0rNPM", "Knee Socks": "00bk5E7gecI", "That's Where You're Wrong": "tLOUVbemjro", "Leave Before the Lights Come On": "SEukS2YN9B8", "I Want It All": "SDTxuAEPfdY", "Secret Door": "ibyGhbvo94Q", "Suck It and See": "rjFGapDkSM0", "7": "R2t6vgC_OWw", "Brianstorm": "30w8DyEJ__0", "Baby I'm Yours": "EDLhMf6voq8", "Arabella": "Nj8r3qmOoZ8", "Old Yellow Bricks": "xLaeOrDmWQ4", "Don't Forget Whose Legs You're On": "qL0Z3Ly0CEw", "Riot Van": "j052-ROwPFM", "What If You Were Right the First Time?": "t2cFvzmqmwc", "Fire and the Thud": "VGlhSSP4nTk", "I Wanna Be Yours": "Y4NGoS330HE", "Mad Sounds": "J_-FwyoeV3E", "Fireside": "PG8yTUeptFU", "The Afternoon's Hat": "qbNKclt42Xc", "Reckless Serenade": "PY2FQ-LgmYo", "No Buses": "WK4wISbGvJw", "Electricity": "g-cukZ10j8A", "Little Illusion Machine (Wirral Riddler) ": "WlMzuzud8U4", "Piledriver Waltz": "njirT4N-JxU", "When the Sun Goes Down": "EqkBRVukQmE", "No. 1 Party Anthem": "83hFiC-siDs", "Evil Twin": "xwir-pg7WiA", "This House Is a Circus": "oDB-MGsWzQQ", "I Haven't Got My Strange": "a9yrz_psfLc", "Black Treacle": "1wznj4lD1Bs", "505": "ifZfUVp2chE", "Dangerous Animals": "qHe3E366_Po", "Perhaps Vampires Is a Bit Strong But..": "SjzOUf0AEiQ", "Fluorescent Adolescent": "ma9I9VBKPiw", "Library Pictures": "bmVerkoFPJU", "The View from the Afternoon": "PeQAZsyucbQ", "Despair in the Departure Lounge": "ZLS8ffCYN80", "I Bet You Look Good on the Dancefloor": "pK7egZaT3hs", "Bigger Boys and Stolen Sweethearts": "rLkikLrImnk", "Balaclava": "6LBCqG0YnTM", "Fake Tales of San Francisco": "ePg1tbia9Bg", "D Is for Dangerous": "zOlhvxPC3MQ", "Put Your Dukes Up John": "O8Wuv1WKldk", "My Propeller": "Z5vZovv8cPk", "Red Right Hand": "hcvGOUuDGXc", "One for the Road": "qN7gSMPQFss", "Joining the Dots": "wkvUl_l3o1c", "Red Light Indicates Doors Are Secured": "hdmR58BIHOg", "You and I ": "9zXkAaoBOLU", "Teddy Picker": "2A2XBoxtcUA", "Settle for a Draw": "IQ7NH2jcAAw", "Bad Woman ": "YnkJHU3qYIA", "Cornerstone": "LIQz6zZi7R0", "Fright Lined Dining Room": "qrqtD4TiO5c", "A Certain Romance": "WGyj5JyA5Ms", "If You Found This It's Probably Too Late": "SqKl1vcmvOU", "Who the Fuck Are Arctic Monkeys?": "oFeuKVkau6U", "Do Me a Favour": "lXJEDlLepD4", "You Probably Couldn't See for the Lights but You Were Staring Straight at Me": "j8iV3tK717s", "Dancing Shoes": "3aQELo7tXyI", "The Jeweller's Hands": "1rq0Ag15sAI", "Matador/Da Frame 2R": "DxoPxvJ0FNM", "Pretty Visitors": "4n7iaY22Do0", "You're So Dark": "6eoAwXkI3RA"}

    var score = 0
    var nb = 0
    var iter = 0
    var song
    var start
    var click
    var listSongs = []

    getHome()

    $(document).on("click", '.calc_btn', function() {

        iter++
        $("#valueIter").html(iter+"/10")
        if(iter == 10)
        {
            gameOver(score)
        }
        else 
        {
            click = new Date()
            time = (click.getTime() - start.getTime())/1000
            if($(this).val() == song){
                if(time <= 15)
                    score += parseInt((-1000/14)*time+929)
                $("#valueScore").html(score)
                $("#valueScore").css( "color", "green" )
            } 
            else
            {
                $("#valueScore").html(score)
                $("#valueScore").css( "color", "red" )
            }
            nb += 1
            getSong()
        }
    })

    function getHome()
    {
        score = 0
        iter = 0
        listSongs = []
        $("#boardGame").html("<h2>Welcome to The Game of Monkeys</h2><table class='calculatrice' id='calc'><tbody><tr><td class='calc_td_btn'><input type='button' class='stres' value='Start' onclick='getSong()'></td></tr></tbody></table")
    }

    function getSong()
    {
        var keys = [];
        for (var prop in json_dic) {
            if (json_dic.hasOwnProperty(prop)) {
                keys.push(prop);
            }
        }

        song = keys[ keys.length * Math.random() << 0 ];
        listSongs = [ song ]
        url = json_dic[song]

        while(listSongs.length <= 4)
        {
            var keys = [];
            for (var prop in json_dic) {
                if (json_dic.hasOwnProperty(prop)) {
                    keys.push(prop);
                }
            }

            song_random = keys[ keys.length * Math.random() << 0 ];
            listSongs.push(song_random)
        }

        $("#boardGame").html('<table class="calculatrice" id="calc"> '+
            '<tbody>' +
            '<tr>' +
            '<td class="calc_td_btn">' +
            '<div style="position:relative;width:380px;height:25px;overflow:hidden;">' +
            '<div id="yt_video" style="position:absolute;top:-276px;left:-5px">' +
            '</div>' +
            '</div>' +
            '</td>' +
            '</tr>');

        for(var i = 0; i <= 4; i++)
        {
            var randomIndex = Math.floor(Math.random() * listSongs.length);
            var randomString = listSongs[randomIndex];
            $("#boardGame").append('<tr>'+
                '<td class="calc_td_btn">' +
                '<input type="button" class="calc_btn" value="'+randomString+'">' +
                '</td>' +
                '</tr>')
            var index = listSongs.indexOf(randomString);
            listSongs.splice(index, 1);
        }

        $("#boardGame").append('<tr>' +
            '<td class="calc_td_btn">' +
            '<h2 id="valueScore">0 points</h2>' +
            '<h2 id="valueIter">0/10</h2>' +
            '<input type="button" class="stres" onclick="getHome()" value="Restart">' +
            '</td>' +
            '</tr>' +
            '</tbody>' +
            '</table>')

        var nb = getRandomInt(0,100)
        $("#yt_video").html("<iframe src='https://www.youtube.com/embed/"+url+"?autoplay=0&start="+nb+"' id='yt_video' width='380' height='300'></iframe>")

        start = new Date()

    }

    function getRandomInt (min, max) {
        return Math.floor(Math.random() * (max - min + 1)) + min;
    }

    function gameOver(score){
        $("#boardGame").html("<h2>You scored "+score+" points</h2><table class='calculatrice' id='calc'><tbody><tr><td class='calc_td_btn'><input type='button' onclick='getHome()' class='stres' value='Restart'></td></tr></tbody></table")
    }

</script>




</body>
</html>
作为替代方案,请尝试执行以下操作:

<div id="boardGame">
</div>

<script type="text/javascript">

    json_dic = {"Too Much to Ask": "oHRjgi6sniY", "Sketchead": "GEfpkuCPjXs", "If You Were There, Beware": "ZVOwOzL9uDQ", "Plastic Tramp": "BiVXU2jt1Xo", "The Death Ramps": "p7cijGnXUJM", "Don't Sit Down 'Cause I've Moved Your Chair": "h1vYbHHhqYE", "R U Mine?": "VQH8ZTgna3Q", "2013": "O4vkZUC4VPA", "The Bakery": "P_D1Eqa2Lk4", "Potion Approaching": "Urw780t52zc", "Still Take You Home": "FKPKSK1nCKY", "Chun-Li's Spinning Bird Kick": "4lOdBxVS16o", "Come Together": "a-5tTz8flYI", "Snap Out of It": "PHoSRT2fNME", "Cigarette Smoker Fiona": "Wg89x455WK4", "Why'd You Only Call Me When You're High?": "6366dxFf-Os", "Brick by Brick": "qOTRx3ZqjjI", "Temptation Greets You Like Your Naughty Friend ": "VEWNOzgnmq0", "The Blond-O-Sonic Shimmer Trap": "EyBrLYN2Yok", "The Bad Thing": "3xTHjLf-ONg", "All My Own Stunts": "Er3r_J-mwII", "Love Is a Laserquest": "wxQVpRSxOZ0", "Dance Little Liar": "hf-B3Y3B0TQ", "Mardy Bum": "Lp1fQ51YZMM", "Stickin' to the Floor": "AQVMJkZGpSc", "Only Ones Who Know": "m-seRFY7-cw", "Crying Lightning": "fLsBJPlGIDU", "From the Ritz to the Rubble ": "givRh52Ic3A", "I.D.S.T.": "V6yORYEiLyU", "She's Thunderstorms": "tvHz5Rti0cU", "Catapult": "U3LsJMLWN2k", "Stop the World I Wanna Get Off with You": "3PyoxMSEHYI", "The Hellcat Spangled Shalalala": "dAlRXC19hmE", "Do I Wanna Know?": "bpOSxM0rNPM", "Knee Socks": "00bk5E7gecI", "That's Where You're Wrong": "tLOUVbemjro", "Leave Before the Lights Come On": "SEukS2YN9B8", "I Want It All": "SDTxuAEPfdY", "Secret Door": "ibyGhbvo94Q", "Suck It and See": "rjFGapDkSM0", "7": "R2t6vgC_OWw", "Brianstorm": "30w8DyEJ__0", "Baby I'm Yours": "EDLhMf6voq8", "Arabella": "Nj8r3qmOoZ8", "Old Yellow Bricks": "xLaeOrDmWQ4", "Don't Forget Whose Legs You're On": "qL0Z3Ly0CEw", "Riot Van": "j052-ROwPFM", "What If You Were Right the First Time?": "t2cFvzmqmwc", "Fire and the Thud": "VGlhSSP4nTk", "I Wanna Be Yours": "Y4NGoS330HE", "Mad Sounds": "J_-FwyoeV3E", "Fireside": "PG8yTUeptFU", "The Afternoon's Hat": "qbNKclt42Xc", "Reckless Serenade": "PY2FQ-LgmYo", "No Buses": "WK4wISbGvJw", "Electricity": "g-cukZ10j8A", "Little Illusion Machine (Wirral Riddler) ": "WlMzuzud8U4", "Piledriver Waltz": "njirT4N-JxU", "When the Sun Goes Down": "EqkBRVukQmE", "No. 1 Party Anthem": "83hFiC-siDs", "Evil Twin": "xwir-pg7WiA", "This House Is a Circus": "oDB-MGsWzQQ", "I Haven't Got My Strange": "a9yrz_psfLc", "Black Treacle": "1wznj4lD1Bs", "505": "ifZfUVp2chE", "Dangerous Animals": "qHe3E366_Po", "Perhaps Vampires Is a Bit Strong But..": "SjzOUf0AEiQ", "Fluorescent Adolescent": "ma9I9VBKPiw", "Library Pictures": "bmVerkoFPJU", "The View from the Afternoon": "PeQAZsyucbQ", "Despair in the Departure Lounge": "ZLS8ffCYN80", "I Bet You Look Good on the Dancefloor": "pK7egZaT3hs", "Bigger Boys and Stolen Sweethearts": "rLkikLrImnk", "Balaclava": "6LBCqG0YnTM", "Fake Tales of San Francisco": "ePg1tbia9Bg", "D Is for Dangerous": "zOlhvxPC3MQ", "Put Your Dukes Up John": "O8Wuv1WKldk", "My Propeller": "Z5vZovv8cPk", "Red Right Hand": "hcvGOUuDGXc", "One for the Road": "qN7gSMPQFss", "Joining the Dots": "wkvUl_l3o1c", "Red Light Indicates Doors Are Secured": "hdmR58BIHOg", "You and I ": "9zXkAaoBOLU", "Teddy Picker": "2A2XBoxtcUA", "Settle for a Draw": "IQ7NH2jcAAw", "Bad Woman ": "YnkJHU3qYIA", "Cornerstone": "LIQz6zZi7R0", "Fright Lined Dining Room": "qrqtD4TiO5c", "A Certain Romance": "WGyj5JyA5Ms", "If You Found This It's Probably Too Late": "SqKl1vcmvOU", "Who the Fuck Are Arctic Monkeys?": "oFeuKVkau6U", "Do Me a Favour": "lXJEDlLepD4", "You Probably Couldn't See for the Lights but You Were Staring Straight at Me": "j8iV3tK717s", "Dancing Shoes": "3aQELo7tXyI", "The Jeweller's Hands": "1rq0Ag15sAI", "Matador/Da Frame 2R": "DxoPxvJ0FNM", "Pretty Visitors": "4n7iaY22Do0", "You're So Dark": "6eoAwXkI3RA"}

    var score = 0
    var nb = 0
    var iter = 0
    var song
    var start
    var click
    var listSongs = []

    getHome()

    $(document).on("click", '.calc_btn', function() {

        iter++
        $("#valueIter").html(iter+"/10")
        if(iter == 10)
        {
            gameOver(score)
        }
        else 
        {
            click = new Date()
            time = (click.getTime() - start.getTime())/1000
            if($(this).val() == song){
                if(time <= 15)
                    score += parseInt((-1000/14)*time+929)
                $("#valueScore").html(score)
                $("#valueScore").css( "color", "green" )
            } 
            else
            {
                $("#valueScore").html(score)
                $("#valueScore").css( "color", "red" )
            }
            nb += 1
            getSong()
        }
    })

    function getHome()
    {
        score = 0
        iter = 0
        listSongs = []
        $("#boardGame").html("<h2>Welcome to The Game of Monkeys</h2><table class='calculatrice' id='calc'><tbody><tr><td class='calc_td_btn'><input type='button' class='stres' value='Start' onclick='getSong()'></td></tr></tbody></table")
    }

    function getSong()
    {
        var keys = [];
        for (var prop in json_dic) {
            if (json_dic.hasOwnProperty(prop)) {
                keys.push(prop);
            }
        }

        song = keys[ keys.length * Math.random() << 0 ];
        listSongs = [ song ]
        url = json_dic[song]

        while(listSongs.length <= 4)
        {
            var keys = [];
            for (var prop in json_dic) {
                if (json_dic.hasOwnProperty(prop)) {
                    keys.push(prop);
                }
            }

            song_random = keys[ keys.length * Math.random() << 0 ];
            listSongs.push(song_random)
        }

        $("#boardGame").html('<table class="calculatrice" id="calc"> '+
            '<tbody>' +
            '<tr>' +
            '<td class="calc_td_btn">' +
            '<div style="position:relative;width:380px;height:25px;overflow:hidden;">' +
            '<div id="yt_video" style="position:absolute;top:-276px;left:-5px">' +
            '</div>' +
            '</div>' +
            '</td>' +
            '</tr>');

        for(var i = 0; i <= 4; i++)
        {
            var randomIndex = Math.floor(Math.random() * listSongs.length);
            var randomString = listSongs[randomIndex];
            $("#boardGame").append('<tr>'+
                '<td class="calc_td_btn">' +
                '<input type="button" class="calc_btn" value="'+randomString+'">' +
                '</td>' +
                '</tr>')
            var index = listSongs.indexOf(randomString);
            listSongs.splice(index, 1);
        }

        $("#boardGame").append('<tr>' +
            '<td class="calc_td_btn">' +
            '<h2 id="valueScore">0 points</h2>' +
            '<h2 id="valueIter">0/10</h2>' +
            '<input type="button" class="stres" onclick="getHome()" value="Restart">' +
            '</td>' +
            '</tr>' +
            '</tbody>' +
            '</table>')

        var nb = getRandomInt(0,100)
        $("#yt_video").html("<iframe src='https://www.youtube.com/embed/"+url+"?autoplay=0&start="+nb+"' id='yt_video' width='380' height='300'></iframe>")

        start = new Date()

    }

    function getRandomInt (min, max) {
        return Math.floor(Math.random() * (max - min + 1)) + min;
    }

    function gameOver(score){
        $("#boardGame").html("<h2>You scored "+score+" points</h2><table class='calculatrice' id='calc'><tbody><tr><td class='calc_td_btn'><input type='button' onclick='getHome()' class='stres' value='Restart'></td></tr></tbody></table")
    }

</script>




</body>
</html>
  • 为所有多选按钮指定一个类:'.choice_button'
  • 在所有按钮周围放置一个
    ,这样您就可以在其中插入新按钮
  • 与其替换“#boardGame”的HTML,只需销毁所有按钮:
    $(“#button_wrapper.choice_button”)。删除()
  • 现在,您可以使用
    for
    循环插入新按钮,就像您在第93行所做的那样
  • 现在,
    $(“#valueScore”)
    还没有被吹走,所以分数应该保持不变
  • 我修改了您的代码,使其达到我认为您所追求的目标:

    <div id="boardGame">
    </div>
    
    <script type="text/javascript">
    
        json_dic = {"Too Much to Ask": "oHRjgi6sniY", "Sketchead": "GEfpkuCPjXs", "If You Were There, Beware": "ZVOwOzL9uDQ", "Plastic Tramp": "BiVXU2jt1Xo", "The Death Ramps": "p7cijGnXUJM", "Don't Sit Down 'Cause I've Moved Your Chair": "h1vYbHHhqYE", "R U Mine?": "VQH8ZTgna3Q", "2013": "O4vkZUC4VPA", "The Bakery": "P_D1Eqa2Lk4", "Potion Approaching": "Urw780t52zc", "Still Take You Home": "FKPKSK1nCKY", "Chun-Li's Spinning Bird Kick": "4lOdBxVS16o", "Come Together": "a-5tTz8flYI", "Snap Out of It": "PHoSRT2fNME", "Cigarette Smoker Fiona": "Wg89x455WK4", "Why'd You Only Call Me When You're High?": "6366dxFf-Os", "Brick by Brick": "qOTRx3ZqjjI", "Temptation Greets You Like Your Naughty Friend ": "VEWNOzgnmq0", "The Blond-O-Sonic Shimmer Trap": "EyBrLYN2Yok", "The Bad Thing": "3xTHjLf-ONg", "All My Own Stunts": "Er3r_J-mwII", "Love Is a Laserquest": "wxQVpRSxOZ0", "Dance Little Liar": "hf-B3Y3B0TQ", "Mardy Bum": "Lp1fQ51YZMM", "Stickin' to the Floor": "AQVMJkZGpSc", "Only Ones Who Know": "m-seRFY7-cw", "Crying Lightning": "fLsBJPlGIDU", "From the Ritz to the Rubble ": "givRh52Ic3A", "I.D.S.T.": "V6yORYEiLyU", "She's Thunderstorms": "tvHz5Rti0cU", "Catapult": "U3LsJMLWN2k", "Stop the World I Wanna Get Off with You": "3PyoxMSEHYI", "The Hellcat Spangled Shalalala": "dAlRXC19hmE", "Do I Wanna Know?": "bpOSxM0rNPM", "Knee Socks": "00bk5E7gecI", "That's Where You're Wrong": "tLOUVbemjro", "Leave Before the Lights Come On": "SEukS2YN9B8", "I Want It All": "SDTxuAEPfdY", "Secret Door": "ibyGhbvo94Q", "Suck It and See": "rjFGapDkSM0", "7": "R2t6vgC_OWw", "Brianstorm": "30w8DyEJ__0", "Baby I'm Yours": "EDLhMf6voq8", "Arabella": "Nj8r3qmOoZ8", "Old Yellow Bricks": "xLaeOrDmWQ4", "Don't Forget Whose Legs You're On": "qL0Z3Ly0CEw", "Riot Van": "j052-ROwPFM", "What If You Were Right the First Time?": "t2cFvzmqmwc", "Fire and the Thud": "VGlhSSP4nTk", "I Wanna Be Yours": "Y4NGoS330HE", "Mad Sounds": "J_-FwyoeV3E", "Fireside": "PG8yTUeptFU", "The Afternoon's Hat": "qbNKclt42Xc", "Reckless Serenade": "PY2FQ-LgmYo", "No Buses": "WK4wISbGvJw", "Electricity": "g-cukZ10j8A", "Little Illusion Machine (Wirral Riddler) ": "WlMzuzud8U4", "Piledriver Waltz": "njirT4N-JxU", "When the Sun Goes Down": "EqkBRVukQmE", "No. 1 Party Anthem": "83hFiC-siDs", "Evil Twin": "xwir-pg7WiA", "This House Is a Circus": "oDB-MGsWzQQ", "I Haven't Got My Strange": "a9yrz_psfLc", "Black Treacle": "1wznj4lD1Bs", "505": "ifZfUVp2chE", "Dangerous Animals": "qHe3E366_Po", "Perhaps Vampires Is a Bit Strong But..": "SjzOUf0AEiQ", "Fluorescent Adolescent": "ma9I9VBKPiw", "Library Pictures": "bmVerkoFPJU", "The View from the Afternoon": "PeQAZsyucbQ", "Despair in the Departure Lounge": "ZLS8ffCYN80", "I Bet You Look Good on the Dancefloor": "pK7egZaT3hs", "Bigger Boys and Stolen Sweethearts": "rLkikLrImnk", "Balaclava": "6LBCqG0YnTM", "Fake Tales of San Francisco": "ePg1tbia9Bg", "D Is for Dangerous": "zOlhvxPC3MQ", "Put Your Dukes Up John": "O8Wuv1WKldk", "My Propeller": "Z5vZovv8cPk", "Red Right Hand": "hcvGOUuDGXc", "One for the Road": "qN7gSMPQFss", "Joining the Dots": "wkvUl_l3o1c", "Red Light Indicates Doors Are Secured": "hdmR58BIHOg", "You and I ": "9zXkAaoBOLU", "Teddy Picker": "2A2XBoxtcUA", "Settle for a Draw": "IQ7NH2jcAAw", "Bad Woman ": "YnkJHU3qYIA", "Cornerstone": "LIQz6zZi7R0", "Fright Lined Dining Room": "qrqtD4TiO5c", "A Certain Romance": "WGyj5JyA5Ms", "If You Found This It's Probably Too Late": "SqKl1vcmvOU", "Who the Fuck Are Arctic Monkeys?": "oFeuKVkau6U", "Do Me a Favour": "lXJEDlLepD4", "You Probably Couldn't See for the Lights but You Were Staring Straight at Me": "j8iV3tK717s", "Dancing Shoes": "3aQELo7tXyI", "The Jeweller's Hands": "1rq0Ag15sAI", "Matador/Da Frame 2R": "DxoPxvJ0FNM", "Pretty Visitors": "4n7iaY22Do0", "You're So Dark": "6eoAwXkI3RA"}
    
        var score = 0
        var nb = 0
        var iter = 0
        var song
        var start
        var click
        var listSongs = []
    
        getHome()
    
        $(document).on("click", '.calc_btn', function() {
    
            iter++
            $("#valueIter").html(iter+"/10")
            if(iter == 10)
            {
                gameOver(score)
            }
            else 
            {
                click = new Date()
                time = (click.getTime() - start.getTime())/1000
                if($(this).val() == song){
                    if(time <= 15)
                        score += parseInt((-1000/14)*time+929)
                    $("#valueScore").html(score)
                    $("#valueScore").css( "color", "green" )
                } 
                else
                {
                    $("#valueScore").html(score)
                    $("#valueScore").css( "color", "red" )
                }
                nb += 1
                getSong()
            }
        })
    
        function getHome()
        {
            score = 0
            iter = 0
            listSongs = []
            $("#boardGame").html("<h2>Welcome to The Game of Monkeys</h2><table class='calculatrice' id='calc'><tbody><tr><td class='calc_td_btn'><input type='button' class='stres' value='Start' onclick='getSong()'></td></tr></tbody></table")
        }
    
        function getSong()
        {
            var keys = [];
            for (var prop in json_dic) {
                if (json_dic.hasOwnProperty(prop)) {
                    keys.push(prop);
                }
            }
    
            song = keys[ keys.length * Math.random() << 0 ];
            listSongs = [ song ]
            url = json_dic[song]
    
            while(listSongs.length <= 4)
            {
                var keys = [];
                for (var prop in json_dic) {
                    if (json_dic.hasOwnProperty(prop)) {
                        keys.push(prop);
                    }
                }
    
                song_random = keys[ keys.length * Math.random() << 0 ];
                listSongs.push(song_random)
            }
    
            $("#boardGame").html('<table class="calculatrice" id="calc"> '+
                '<tbody>' +
                '<tr>' +
                '<td class="calc_td_btn">' +
                '<div style="position:relative;width:380px;height:25px;overflow:hidden;">' +
                '<div id="yt_video" style="position:absolute;top:-276px;left:-5px">' +
                '</div>' +
                '</div>' +
                '</td>' +
                '</tr>');
    
            for(var i = 0; i <= 4; i++)
            {
                var randomIndex = Math.floor(Math.random() * listSongs.length);
                var randomString = listSongs[randomIndex];
                $("#boardGame").append('<tr>'+
                    '<td class="calc_td_btn">' +
                    '<input type="button" class="calc_btn" value="'+randomString+'">' +
                    '</td>' +
                    '</tr>')
                var index = listSongs.indexOf(randomString);
                listSongs.splice(index, 1);
            }
    
            $("#boardGame").append('<tr>' +
                '<td class="calc_td_btn">' +
                '<h2 id="valueScore">0 points</h2>' +
                '<h2 id="valueIter">0/10</h2>' +
                '<input type="button" class="stres" onclick="getHome()" value="Restart">' +
                '</td>' +
                '</tr>' +
                '</tbody>' +
                '</table>')
    
            var nb = getRandomInt(0,100)
            $("#yt_video").html("<iframe src='https://www.youtube.com/embed/"+url+"?autoplay=0&start="+nb+"' id='yt_video' width='380' height='300'></iframe>")
    
            start = new Date()
    
        }
    
        function getRandomInt (min, max) {
            return Math.floor(Math.random() * (max - min + 1)) + min;
        }
    
        function gameOver(score){
            $("#boardGame").html("<h2>You scored "+score+" points</h2><table class='calculatrice' id='calc'><tbody><tr><td class='calc_td_btn'><input type='button' onclick='getHome()' class='stres' value='Restart'></td></tr></tbody></table")
        }
    
    </script>
    
    
    
    
    </body>
    </html>
    
    <div id="boardGame">
    </div>
    
    <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
    <script type="text/javascript">
    
        json_dic = {"Too Much to Ask": "oHRjgi6sniY", "Sketchead": "GEfpkuCPjXs", "If You Were There, Beware": "ZVOwOzL9uDQ", "Plastic Tramp": "BiVXU2jt1Xo", "The Death Ramps": "p7cijGnXUJM", "Don't Sit Down 'Cause I've Moved Your Chair": "h1vYbHHhqYE", "R U Mine?": "VQH8ZTgna3Q", "2013": "O4vkZUC4VPA", "The Bakery": "P_D1Eqa2Lk4", "Potion Approaching": "Urw780t52zc", "Still Take You Home": "FKPKSK1nCKY", "Chun-Li's Spinning Bird Kick": "4lOdBxVS16o", "Come Together": "a-5tTz8flYI", "Snap Out of It": "PHoSRT2fNME", "Cigarette Smoker Fiona": "Wg89x455WK4", "Why'd You Only Call Me When You're High?": "6366dxFf-Os", "Brick by Brick": "qOTRx3ZqjjI", "Temptation Greets You Like Your Naughty Friend ": "VEWNOzgnmq0", "The Blond-O-Sonic Shimmer Trap": "EyBrLYN2Yok", "The Bad Thing": "3xTHjLf-ONg", "All My Own Stunts": "Er3r_J-mwII", "Love Is a Laserquest": "wxQVpRSxOZ0", "Dance Little Liar": "hf-B3Y3B0TQ", "Mardy Bum": "Lp1fQ51YZMM", "Stickin' to the Floor": "AQVMJkZGpSc", "Only Ones Who Know": "m-seRFY7-cw", "Crying Lightning": "fLsBJPlGIDU", "From the Ritz to the Rubble ": "givRh52Ic3A", "I.D.S.T.": "V6yORYEiLyU", "She's Thunderstorms": "tvHz5Rti0cU", "Catapult": "U3LsJMLWN2k", "Stop the World I Wanna Get Off with You": "3PyoxMSEHYI", "The Hellcat Spangled Shalalala": "dAlRXC19hmE", "Do I Wanna Know?": "bpOSxM0rNPM", "Knee Socks": "00bk5E7gecI", "That's Where You're Wrong": "tLOUVbemjro", "Leave Before the Lights Come On": "SEukS2YN9B8", "I Want It All": "SDTxuAEPfdY", "Secret Door": "ibyGhbvo94Q", "Suck It and See": "rjFGapDkSM0", "7": "R2t6vgC_OWw", "Brianstorm": "30w8DyEJ__0", "Baby I'm Yours": "EDLhMf6voq8", "Arabella": "Nj8r3qmOoZ8", "Old Yellow Bricks": "xLaeOrDmWQ4", "Don't Forget Whose Legs You're On": "qL0Z3Ly0CEw", "Riot Van": "j052-ROwPFM", "What If You Were Right the First Time?": "t2cFvzmqmwc", "Fire and the Thud": "VGlhSSP4nTk", "I Wanna Be Yours": "Y4NGoS330HE", "Mad Sounds": "J_-FwyoeV3E", "Fireside": "PG8yTUeptFU", "The Afternoon's Hat": "qbNKclt42Xc", "Reckless Serenade": "PY2FQ-LgmYo", "No Buses": "WK4wISbGvJw", "Electricity": "g-cukZ10j8A", "Little Illusion Machine (Wirral Riddler) ": "WlMzuzud8U4", "Piledriver Waltz": "njirT4N-JxU", "When the Sun Goes Down": "EqkBRVukQmE", "No. 1 Party Anthem": "83hFiC-siDs", "Evil Twin": "xwir-pg7WiA", "This House Is a Circus": "oDB-MGsWzQQ", "I Haven't Got My Strange": "a9yrz_psfLc", "Black Treacle": "1wznj4lD1Bs", "505": "ifZfUVp2chE", "Dangerous Animals": "qHe3E366_Po", "Perhaps Vampires Is a Bit Strong But..": "SjzOUf0AEiQ", "Fluorescent Adolescent": "ma9I9VBKPiw", "Library Pictures": "bmVerkoFPJU", "The View from the Afternoon": "PeQAZsyucbQ", "Despair in the Departure Lounge": "ZLS8ffCYN80", "I Bet You Look Good on the Dancefloor": "pK7egZaT3hs", "Bigger Boys and Stolen Sweethearts": "rLkikLrImnk", "Balaclava": "6LBCqG0YnTM", "Fake Tales of San Francisco": "ePg1tbia9Bg", "D Is for Dangerous": "zOlhvxPC3MQ", "Put Your Dukes Up John": "O8Wuv1WKldk", "My Propeller": "Z5vZovv8cPk", "Red Right Hand": "hcvGOUuDGXc", "One for the Road": "qN7gSMPQFss", "Joining the Dots": "wkvUl_l3o1c", "Red Light Indicates Doors Are Secured": "hdmR58BIHOg", "You and I ": "9zXkAaoBOLU", "Teddy Picker": "2A2XBoxtcUA", "Settle for a Draw": "IQ7NH2jcAAw", "Bad Woman ": "YnkJHU3qYIA", "Cornerstone": "LIQz6zZi7R0", "Fright Lined Dining Room": "qrqtD4TiO5c", "A Certain Romance": "WGyj5JyA5Ms", "If You Found This It's Probably Too Late": "SqKl1vcmvOU", "Who the Fuck Are Arctic Monkeys?": "oFeuKVkau6U", "Do Me a Favour": "lXJEDlLepD4", "You Probably Couldn't See for the Lights but You Were Staring Straight at Me": "j8iV3tK717s", "Dancing Shoes": "3aQELo7tXyI", "The Jeweller's Hands": "1rq0Ag15sAI", "Matador/Da Frame 2R": "DxoPxvJ0FNM", "Pretty Visitors": "4n7iaY22Do0", "You're So Dark": "6eoAwXkI3RA"}
    
        var score = 0
        var nb = 0
        var iter = 0
        var song
        var start
        var click
        var listSongs = []
    
        getHome()
    
        $(document).on("click", '.calc_btn', function() {
    
            iter++
            $("#valueIter").html(iter+"/10")
            if(iter == 10)
            {
                gameOver(score)
            }
            else 
            {
                click = new Date()
                time = (click.getTime() - start.getTime())/1000
                if($(this).val() == song){
                    if(time <= 15)
                        score += parseInt((-1000/14)*time+929)
                    $("#valueScore").html(score)
                    $("#valueScore").css( "color", "green" )
                } 
                else
                {
                    $("#valueScore").html(score)
                    $("#valueScore").css( "color", "red" )
                }
                nb += 1
                getSong()
                return false;
            }
        })
    
        function getHome()
        {
            score = 0
            iter = 0
            listSongs = []
            $("#boardGame").html(
                '<h2>Welcome to The Game of Monkeys</h2>'+
                '<table class="calculatrice" id="calc">' +
                    '<tbody>' +
                    '</tbody>' +
                '</table>' +
                '<div id="gameButtons" style="display: none;">' +
                    '<h2 id="valueScore">0 points</h2>' +
                    '<h2 id="valueIter">0/10</h2>' +
                    '<input type="button" class="stres" onclick="getHome()" value="Restart">' +
                '</div>' +
                '<input type="button" class="stres" value="Start" onclick="getSong()">'
            )
        }
    
        function getSong()
        {
            var keys = [];
            for (var prop in json_dic) {
                if (json_dic.hasOwnProperty(prop)) {
                    keys.push(prop);
                }
            }
    
            song = keys[ keys.length * Math.random() << 0 ];
            listSongs = [ song ]
            url = json_dic[song]
    
            while(listSongs.length <= 4)
            {
                var keys = [];
                for (var prop in json_dic) {
                    if (json_dic.hasOwnProperty(prop)) {
                        keys.push(prop);
                    }
                }
    
                song_random = keys[ keys.length * Math.random() << 0 ];
                listSongs.push(song_random)
            }
    
            // adds the music player, of course
            $('#calc tbody').html (
                '<tr>' +
                '<td class="calc_td_btn">' +
                '<div style="position:relative;width:380px;height:25px;overflow:hidden;">' +
                '<div id="yt_video" style="position:absolute;top:-276px;left:-5px">' +
                '</div>' +
                '</div>' +
                '</td>' +
                '</tr>');
    
            // adds the multiple choice buttons
            for(var i = 0; i <= 4; i++)
            {
                var randomIndex = Math.floor(Math.random() * listSongs.length);
                var randomString = listSongs[randomIndex];
                $("#calc tbody").append('<tr>'+
                    '<td class="calc_td_btn">' +
                    '<input type="button" class="calc_btn" value="'+randomString+'">' +
                    '</td>' +
                    '</tr>')
                var index = listSongs.indexOf(randomString);
                listSongs.splice(index, 1);
            }
    
            // shows the score and the restart button
            $('#gameButtons').show();
    
            var nb = getRandomInt(0,100)
            $("#yt_video").html("<iframe src='https://www.youtube.com/embed/"+url+"?autoplay=0&start="+nb+"' id='yt_video' width='380' height='300'></iframe>")
    
            start = new Date()
    
        }
    
        function getRandomInt (min, max) {
            return Math.floor(Math.random() * (max - min + 1)) + min;
        }
    
        function gameOver(score){
            $("#boardGame").html("<h2>You scored "+score+" points</h2><table class='calculatrice' id='calc'><tbody><tr><td class='calc_td_btn'><input type='button' onclick='getHome()' class='stres' value='Restart'></td></tr></tbody></table")
        }
    
    </script>
    </body>
    </html>
    
    
    json_dic={“要求太多”: