[英]JavaScript array to display different pictures on click not functioning as expected
我目前正在這樣做,以便當您單擊一個數字時,它上面的圖片將發生變化,最終這些圖片將根據其他輸入進行實時更新(如果有人有任何好的想法,即使這是另一個主題) ),這樣的想法是您可以瀏覽並單擊其中一張圖片以獲得更好的外觀。
我已經做好了外發工作,但是我也在努力使外來工作正常。
他們倆都在工作,我想我已經在某個地方取得了成功。
有人幫忙嗎?
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript">
function changeIt(objName)
{
//The image object accessed through its id we mentioned in the DIV block which is going to be visible currently
var obj = document.getElementById(objName);
//An array that hold the IDs of images that we mentioned in their DIV blocks
var objId = new Array();
//Storing the image IDs into the array starts here
objId[0] = "limage1";
objId[1] = "limage2";
objId[2] = "limage3";
objId[3] = "limage4";
objId[4] = "limage5";
//Storing the image IDs into the array ends here
//A counter variable going to use for iteration
var i;
//A variable that can hold all the other object references other than the object which is going to be visible
var tempObj;
//The following loop does the display of a single image based on its ID. The image whose ID we passed into this function will be the
//only image that is displayed rest of the images will be hidden based on their IDs and that part has been handled by the else part
//of the if statement within this loop.
for(i=0;i<objId.length;i++)
{
if(objName == objId[i])
{
obj.style.display = "block";
}
else
{
tempObj = document.getElementById(objId[i]);
tempObj.style.display = "none";
}
}
return;
}
</script>
<script type="text/javascript">
function changeIt(objName)
{
//The image object accessed through its id we mentioned in the DIV block which is going to be visible currently
var obj = document.getElementById(objName);
//An array that hold the IDs of images that we mentioned in their DIV blocks
var objId = new Array();
//Storing the image IDs into the array starts here
objId[0] = "rimage1";
objId[1] = "rimage2";
objId[2] = "rimage3";
objId[3] = "rimage4";
objId[4] = "rimage5";
//Storing the image IDs into the array ends here
//A counter variable going to use for iteration
var j;
//A variable that can hold all the other object references other than the object which is going to be visible
var tempObj;
//The following loop does the display of a single image based on its ID. The image whose ID we passed into this function will be the
//only image that is displayed rest of the images will be hidden based on their IDs and that part has been handled by the else part
//of the if statement within this loop.
for(j=0;j<objId.length;j++)
{
if(objName == objId[j])
{
obj.style.display = "block";
}
else
{
tempObj = document.getElementById(objId[j]);
tempObj.style.display = "none";
}
}
return;
}
</script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.