【发布时间】:2013-10-19 09:13:08
【问题描述】:
我遇到的问题看起来很简单,但我似乎找不到任何与我的问题相关的资源。我想要做的是使用 Javascript 将 36 个图像从我的计算机内的一个文件夹中存储到一个数组中。下面是相关sn-ps代码的缩短版。
<!doctype html>
<head>
<style>
div#GameBoard {
position: absolute;
top: 66px;
left: 53px;
display: block;
margin: 10px;
padding: 10px;
border: ridge #7CFC00 15px;
width: 1007px;
height: 698px;
}
div#Flipper {
display: block;
position: relative;
background-color: #000;
}
<style>
<script lang="javascript">
var ImgArray = [[11-16][21-26][31-36][41-46][51-56][61-66]];
// pseudocode, the first digit is for row, second digit is for column number.
//I've named the pictures accordingly within the folder as 11.png,12.png,21.png,
//and within the array //as well.
function OnClickCard(path)
{
path || path ='C:\Users\Jamal\Desktop\codefolder\memorygame\gameimages'
document.getElementById("Flipper").img.src = ImgArray.splice(Math.floor(Math.random() * ImgArray.length)[ImgArray];
}
</script>
<body>
<div id="GameBoard">
<div class="Tile" id="Flipper">
<img name ="11" src="blue-glass-tile.png" onclick="OnClickCard()"/>
</div>
</body>
</head>
</html>
所以我想要它做的是将 'C:\Users\Jamal\Desktop\codefolder\memorygame\gameimages' 中的 36 个图像保存在一个数组中,并拼接一个从 0-35 的随机索引以更改为div 中的图像源,删除该索引,使其不会被使用两次。
实际发生的事情......什么都不是。我一直在 Firefox 中为开发者控制台运行它并清除了所有错误,但实际上什么也没发生。我不知道如何运行控制台日志以检测是否已加载图像。我很茫然,甚至跳过了逻辑。在这个时间点上,我迫切需要完成随机化程序,这让我发疯。非常感谢您提供的任何意见。
【问题讨论】:
标签: javascript arrays image path