Javascript 当用户单击3个图像时,用数组中的新随机图像替换图像

Javascript 当用户单击3个图像时,用数组中的新随机图像替换图像,javascript,jquery,Javascript,Jquery,我是个新手,我一直在尝试制作一个网络脚本游戏。我有12张随机生成的卡片,我似乎无法用javascript或jquery编写一种方法来让所有三张卡片消失,并被一个数组中的三张新随机图像替换。正在寻找在我的代码末尾添加此内容的方法。任何帮助都将不胜感激。提前谢谢你 function getRandomImage(imgAr, path) { //getRandomImage is the load script of the twelve random cards generated fo

我是个新手,我一直在尝试制作一个网络脚本游戏。我有12张随机生成的卡片,我似乎无法用javascript或jquery编写一种方法来让所有三张卡片消失,并被一个数组中的三张新随机图像替换。正在寻找在我的代码末尾添加此内容的方法。任何帮助都将不胜感激。提前谢谢你

function getRandomImage(imgAr, path) {  //getRandomImage is the load script of the twelve random cards generated
    for (i=1;i<13;i++) {
        path = path || 'images/'; // default path here
        var num = Math.floor( Math.random() * imgAr.length ); //generating a random img url
        var img = imgAr[ num ];
        imgAr.splice(num, 1) // so that it won't duplicate the same image
        var imgStr = '<button type=button id=replacedCards onclick=replacedCards(set_array)>\n' + '<div class=boxNum' + i + '>' + '\n' + '<img src="' + path + img + '" class = "pic">' + '\n' + '</div>' + '\n' + '</button>';
        oldCards.push(imgStr);
        document.write(imgStr);
        oldCards.splice(0, 12);
        }
        } 

$(document).ready(function() {
$('button').click(function() {
    var url = $(this).find('.pic').attr('src');
    new_array.push(url);
        if ((new_array.length == 3) && ((color(new_array) == false) || (shape(new_array)== false) || (pattern(new_array)==false) || (quantity(new_array)==false))) {
            new_array.splice(0, 3);
            alert('This is not a set!');
        }
        else if ((new_array.length == 3) && ((color(new_array)==true) && (shape(new_array)==true) && (pattern(new_array)==true) && (quantity(new_array)==true)))  {
            alert('This is a set!');
            rps();
            new_array.splice(0,3);
        }


    })
})
函数getRandomImage(imgAr,path){//getRandomImage是生成的12张随机卡的加载脚本
对于(i=1;i