[英]Random images with just 3 images in javascript
有沒有一種方法可以隨機創建一個函數RandomSwapDown(x)
以便每次單擊它時都顯示三個圖像之一? 謝謝。
<script>
function RandomSwapDown(x) {
x.src = '4.gif';
}
function SwapBack(x) {
x.src = 'mouse_over.png';
}
function SwapOut(x) {
x.src = 'mouse_normal.png';
}
</script>
</html>
<div style='top: 200px; left: 175px; position: absolute;'>
<img src='mouse_normal.png' onMouseOver='SwapBack(this)' onMouseOut= 'SwapOut(this)' onMouseDown = 'RandomSwapDown(this)' width="121" height="146" >
<img src='mouse_normal.png' onMouseOver='SwapBack(this)' onMouseOut= 'SwapOut(this)' onMouseDown = 'RandomSwapDown(this)' width="121" height="146" >
<img src='mouse_normal.png' onMouseOver='SwapBack(this)' onMouseOut= 'SwapOut(this)' onMouseDown = 'RandomSwapDown(this)' width="121" height="146" >
</div>
var picArr = []; // array of images to choose from
function RandomSwapDown(x) {
x.src = picArr[Math.floor(Math.random()*3)];
}
function SwapBack(x) {
x.src = picArr[Math.floor(Math.random()*3)];
}
function SwapOut(x) {
x.src = picArr[Math.floor(Math.random()*3)];
}
嗨,我現在不可以在javascript中使用它,但是在java中可以
Random generator=new Random();
int rnd_number;
rnd_number=generator.nextInt(MaxRandom-MinRandom)+MinRandom;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.