我对此很陌生,而且我一直试图制作一个网页剧本游戏。我有十二张随机生成的卡片,我似乎无法用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);
}
})
})