JS无法正常工作

时间:2015-08-25 01:56:57

标签: javascript

我有一个HTML页面,有两个按钮:一个带有onclick="reShuffle('c'),另一个带有onclick="reShuffle('bw')。然后,我有这个Javascript:

function reShuffle(set) {
    if (set = "bw") {
        console.log("Shuffling b&w pictures...");
        var blackAndWhite = shuffle(resize([], 20)); // Second arg is # of images in folder
        go(blackAndWhite, "bw");
    }
    if (set = "c") {
        console.log("Shuffling color pictures...");
        var color = shuffle(resize([],  0)); // Second arg is # of images in folder
        go(color, "c");
    }
    function resize(array, size) {
        for (i = 1; i < size + 1; i++){array.push(i)}
        return array;
    }
    function shuffle(array) {
        var i = array.length,
            j = 0,
            temp;
        while (i--) {
            j = Math.floor(Math.random() * (i+1));
            temp = array[i];
            array[i] = array[j];
            array[j] = temp;
        }
        console.log("Array shuffled: " + String(array));
        console.log("Length: " + array.length);
        return array;
    }
    function go(listName, shortname) {
        for (i = 1; i < 16; i++) { // (i = 1; i < # of <img>; i++)
            var index = listName[i - 1];
            console.log( i + ": " + index + " = " + listName[i - 1]);
            document.getElementById("img" + i + shortname).src="imgs/" + shortname + "/" + index + ".jpg";
        }
    }
}

reShuffle("bw");
reShuffle("c");

问题是,无论我做什么 - reShuffle("bw")reShuffle("c"),来自按钮或控制台,它都会出现问题&#34; reShuffles&#34;两者。

JS所做的是从目录中获取15个随机图像并将它们分配给15个<img>标记。它对我的黑白图像部分执行此操作,因此bw和颜色部分,因此c

0 个答案:

没有答案