0
我不知道我是否可以在變量的指針指定爲沿着我使用eval試過的Javascript動態指針分配
"image"+i+".src"
線的東西,因爲這是我發現的唯一的建議,但我被拋出一個未定義的變量錯誤。這裏是我的代碼,如果有人不介意看看:
<html>
<head>
<script type="text/javascript">
<!--
m = 0
x = 0
image=[ //Initializes the Array for Image URLs, Add object by adding the full URL in "" with , in between each entry
"http://i.imgur.com/OaElB10.jpg",
"http://i.imgur.com/NTYiEB9.jpg",
"http://i.imgur.com/X1jreGc.jpg"]
function ImgPreloadHandler()
{
l = image.length
for(t=0; t<l; t++)
{
var image+t = new image()
image+t = image[t]
}
}
ImgPreloadHandler()
//-->
</script>
</head>
<body>
<img src="http://i.imgur.com/mv3sV8m.png" name="slide" width="796" height="600" />
<script>
function slideit()
{
var step = 0
var z = step
if (!document.images)//if browser does not support the image object, exit.
return
document.images.slide.src=
if (step<x)
step++
else
step=1
setTimeout("slideit()",2500)//call function "slideit()" every 2.5 seconds
}
slideit()
</script>
</body>
</html>
。 –
[JavaScript - 動態變量]的可能重複(http://stackoverflow.com/questions/4385084/javascript-dynamic-variables) –
JavaScript中沒有指針,並且不能手動分配內存。你也不能(不應該)創建動態變量名稱。只需使用你已有的'image'數組! – Bergi