Objective: To obtain the src of img under div
Html:
<Div id = "image1"> </div>
<Div id = "image2"> </div>
.
.
<Div id = "image12"> </div>
My error code:
InitImage ();
LoadImage ();
Function initImage (){
For (var I = 1; I <13; I ++ ){
ImageId [I] = document. getElementById ("image" + I );
}
}
Function loadImage (){
For (var j = 1; j <13; j ++ ){
ImageList [j] = imageId [j]. getElementsByTagName ("img") [0];
If (imageId [j]. src = "images/loading.gif ")
ImageId [j]. src = "images/" + j + ". gif ";
Else ..........
}
}
Code to solve the problem
Copy codeThe Code is as follows:
<Div id = "listimg">
<Div> </div>
<Div> </div>
</Div>
<Script>
Function imglist (obj)
{
Var imglist = document. getElementById (obj). getElementsByTagName ('img ')
For (I = 0; I {
If (imglist [I]. src. indexOf ("loading.gif", 0 )! =-1) {imglist [I]. src = "imgage/" + I + ". gif ";}
Alert (imglist [I]. src) // test successful
}
}
</Script>
<Input onclick = "imglist ('listimg ')" value = "test" type = "button">