Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/371.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 我的脚本没有生成随机图像。有人能告诉我原因是什么吗? var mediaArray=新阵列( “images/Lab13/toshiba.jpg”, “images/Lab13/dell.jpg”, “images/Lab13/acer.jpg” ); var max=mediaArray.length; var指数=0; 函数showMedia() { randomIndex=Math.floor((Math.random()*max)); document.getElementById(“mediaimage”).src=mediaArray[randomIndex]; setTimeout(“showMedia()”,1500); }_Javascript_Random - Fatal编程技术网

Javascript 我的脚本没有生成随机图像。有人能告诉我原因是什么吗? var mediaArray=新阵列( “images/Lab13/toshiba.jpg”, “images/Lab13/dell.jpg”, “images/Lab13/acer.jpg” ); var max=mediaArray.length; var指数=0; 函数showMedia() { randomIndex=Math.floor((Math.random()*max)); document.getElementById(“mediaimage”).src=mediaArray[randomIndex]; setTimeout(“showMedia()”,1500); }

Javascript 我的脚本没有生成随机图像。有人能告诉我原因是什么吗? var mediaArray=新阵列( “images/Lab13/toshiba.jpg”, “images/Lab13/dell.jpg”, “images/Lab13/acer.jpg” ); var max=mediaArray.length; var指数=0; 函数showMedia() { randomIndex=Math.floor((Math.random()*max)); document.getElementById(“mediaimage”).src=mediaArray[randomIndex]; setTimeout(“showMedia()”,1500); },javascript,random,Javascript,Random,当我加载页面时,我认为该函数工作不正常。它加载了第一幅图像“toshiba.jpg”,但它没有像预期的那样更改图像。没有函数ShowMedia()。JS区分大小写。您正在页面加载时调用ShowMedia(): <script type="text/javascript" > var mediaArray = new Array ( "images/Lab13/toshiba.jpg", "images/Lab13/dell.jpg", "images/Lab13/acer.jpg"

当我加载页面时,我认为该函数工作不正常。它加载了第一幅图像“toshiba.jpg”,但它没有像预期的那样更改图像。

没有函数
ShowMedia()
。JS区分大小写。

您正在页面加载时调用
ShowMedia()

<script type="text/javascript" >

var mediaArray = new Array (
"images/Lab13/toshiba.jpg",
"images/Lab13/dell.jpg",
"images/Lab13/acer.jpg"
);

var max = mediaArray.length;
var randomIndex=0;


function showMedia()
{
randomIndex   = Math.floor((Math.random()*max));
document.getElementById("mediaimage").src= mediaArray[randomIndex];
setTimeout("showMedia()",1500);

}
</script>
</head>

<body onLoad="ShowMedia();">
<div><a href="Javascript:mediaClick(randomIndex);">
<img src="images/Lab13/toshiba.jpg" id="mediaimage" /></a>
</div>
</body>

它不存在,因为javascript区分大小写

所以正确的代码应该是:

<body onLoad="ShowMedia();">


这里有一大堆糟糕、过时的技术。您在什么地方找到这个脚本了吗?函数名为
showMedia()
,但您正在调用
showMedia()
。请使用JavaScript错误控制台进行调试。@Albert-如果您将firefox与firebug或chrome的内置检查器一起使用,您可以检查控制台以发现此类问题(在firebug控制台中:“ReferenceError:showMedia未定义”),非常感谢您的帮助!!!
<body onLoad="showMedia();">