你的HTML改成这样:
<div id="lighttable">
<img id="girl1" src="" alt="01" />
<img id="girl2" src="" alt="02" />
<img id="girl3" src="" alt="03" />
etc....
</div>
将这个正确的页面的</head>
标签之前
<script type="text/javascript">
var array = ['http://throwingupthew.com/girls/01.jpg','http://throwingupthew.com/girls/02.jpg','http://throwingupthew.com/girls/03.jpg'];
function shuffle(array) {
var currentIndex = array.length;
var temporaryValue;
var randomIndex;
while (0 !== currentIndex) {
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
return array;
}
var shuffled_images = shuffle(array);
for(var i=0;i<3;i++) {
document.getElementById('girl' + (i+1)).src = shuffled_images[i] ;
}
</script>
由于Randomizing(Shuffling) an Array这个页面,我是能够使这个脚本为你: )
这里是工作JSFiddle :)
通过先做一点研究开始:http://stackoverflow.com/questions/5329201/jquery-move-elements-into-a-random-order – Blender 2013-02-20 01:07:48
你想用JavaScript或...随机化他们吗? – 2013-02-20 01:08:50
我想以最简单的方式随机化。除了调整值来改变结果之外,我对HTML/javascript编码一无所知。 – 2013-02-20 01:12:26