从全局数组中选择图像

时间:2012-02-27 22:06:18

标签: javascript arrays image global onkeypress

关注上一个问题(onkeypress changeImage

我有一个带图像的全局数组:

var globalarray = [["image0.jpg","image1.jpg","image4.jpg","image7.jpg","imageSpace.jpg"],["image1.jpg","image4.jpg","image7.jpg","imageSpace.jpg"], ....... etc];

changeImage功能:

function changeIm(event) {
var code = event.which
  , image
  , directory = 'images/';

if (code == 48 || code == 96) {
    image = 'image0.jpg';
} else if (code == 49 || code == 97) {
    image = 'image1.jpg';
} else if (code == 50 || code == 98) {
    image = 'image2.jpg';
} else if (code == 51 || code == 99) {
    image = 'image3.jpg';
} else if (code == 52 || code == 100) {
    image = 'image4.jpg';
} else if (code == 53 || code == 101) {
    image = 'image5.jpg';
} else if (code == 54 || code == 102) {
    image = 'image6.jpg';
} else if (code == 55 || code == 103) {
    image = 'image7.jpg';
} else if (code == 56 || code == 104) {
    image = 'image8.jpg';
} else if (code == 57 || code == 105) {
    image = 'image9.jpg';
} else {
    image = 'imageSpace.jpg';
}
$('#imageChange').attr('src', directory + image);
}
$('#changeImgInput').keypress(changeIm);

<input size="30" type="text" id="changeImgInput" />

如何只选择每个globalarray中的图像?

示例

如果我选择:

globalarray[0] = ["image0.jpg","image1.jpg","image4.jpg","image7.jpg","imageSpace.jpg"]
globalarray[1] = ["image1.jpg","image4.jpg","image7.jpg","imageSpace.jpg"]
 .
 .
globalarray[10] = [..................]

提前致谢

0 个答案:

没有答案