首先,我很抱歉我的英語不好。 我想問如何使這個腳本,我想把百分比?我的意思是每個圖像都有自己的百分比像一個圖像1有5%顯示圖像2有10%顯示出來並且像那樣?如何使隨機圖像發生器的百分比?
<!DOCTYPE html>
<html>
<body>
<input class="randombutton" type="button" value="Randomize" onclick="randomImg1()"/>
<script type="text/javascript">
function randomImg1() {
myImages1 = new Array();
myImages1[0] = "images/1.gif";
myImages1[1] = "images/2.gif";
\t myImages1[2] = "images/1.gif";
myImages1[3] = "images/2.gif";
\t myImages1[4] = "images/1.gif";
myImages1[5] = "images/2.gif";
\t myImages1[6] = "images/1.gif";
myImages1[7] = "images/2.gif";
\t myImages1[8] = "images/1.gif";
myImages1[9] = "images/2.gif";
\t myImages1[10] = "images/1.gif";
myImages1[11] = "images/2.gif";
\t myImages1[12] = "images/1.gif";
myImages1[13] = "images/2.gif";
\t myImages1[14] = "images/1.gif";
myImages1[15] = "images/2.gif";
\t myImages1[16] = "images/1.gif";
myImages1[17] = "images/2.gif";
\t myImages1[18] = "images/1.gif";
myImages1[19] = "images/2.gif";
var rnd = Math.floor(Math.random() * myImages1.length); //incorporated other solution
document.getElementById("image").innerHTML = "<img src='" + myImages1[rnd] + "' alt='image'></img>";
}
</script>
<div id="image"></div>
</body>
</html>
你有php標籤。該死的,如果是php,我可以輕鬆做到這一點。 – Phiter
嗨,如果這個任何答案已經解決了你的問題,請點擊複選標記,考慮[接受它](http://meta.stackexchange.com/q/5234/179419)。這向更廣泛的社區表明,您已經找到了解決方案,併爲答覆者和您自己提供了一些聲譽。沒有義務這樣做。 – Ofir