To obtain the DIV under the IMG src address of the JS code _ Basic Knowledge

Source: Internet
Author: User
Objective: To obtain the src of div under the img
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 Code code 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 succeeded
}
}
</script>
<input onclick= imglist (' listimg ') '  value= ' Test '  type= ' button ' >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.