我已經嘗試過網站上的各種解決方案,但我懷疑我在執行文檔中的實際圖像或其他任何問題時出錯。先謝謝您的幫助!創建一個JavaScript庫:更改實際圖像
這裏是我當前的代碼:
<html>
<body>
<link type="text/css" rel="stylesheet" href="Stylesheet.css"/>
<img id="teemoimage" src="exampleurl">
<script>
var leagueofteemo=new Array()
var counter = 1
leagueofteemo[1]="exampleurl"
leageuofteemo[2]="exampleurl"
function back()
{
if (counter = 1)
{
counter = leagueofteemo.length;
}
else
{
counter--;
}
document.getElementById("teemoimage").src =leagueofteemo[counter]
}
function foward()
{
if (counter = leageofteemo.length)
{
counter = 1;
}
else
{
counter++;
}
document.getElementById("teemoimage").src = leageuofteemo[counter];
}
</script>
<form>
<input type="button" onclick="back()" value="Back">
<input type="button" onclick="foward()" value="Foward">
</form>
'leagueofteemo'不是'leageofteemo' ......也'leageuofteemo';)嘗試使用變量名稱更易於拼寫。 – ToniTornado