有没有办法随机制作一个函数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>
答案 0 :(得分:0)
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)];
}
答案 1 :(得分:0)
嗨,我现在不能在javascript中使用它,但在java中你可以
Random generator=new Random();
int rnd_number;
rnd_number=generator.nextInt(MaxRandom-MinRandom)+MinRandom;