Home > front end >  Unable to enter the onclick function
Unable to enter the onclick function

Time:09-25

The function prepareHolder () {
if(! Document. The getElementById) return false;
if(! Document. The getElementById (" images ")); return false
Var placeholder=document. The createElement method (" div ");
Placeholder. SetAttribute (" id ", "placeholder");
Var placeimg=document. The createElement method (" img ");
Placeimg. SetAttribute (" id ", "placeimg");
Placeimg. SetAttribute (" SRC ", "images/placeholder. GIF");
Placeholder. The appendChild (placeimg);
Var placetext=document. The createElement method (" p ");
Var description=document. The createTextNode (" choose an image ");
Placetext. SetAttribute (" id ", "placetext");
Placetext. The appendChild (description);
Placeholder. The appendChild (placetext);
Var images=document. GetElementById (" images ");
InsertAfter (placeholder, images);
Var links=images. GetElementsByTagName (" a ");
For (var I=0; i The links [I] onclick=function () {
Var source=this. GetAttribute (" href ");
Var placeholder=document. GetElementById (" placeholder ");
Var placeimg=placeholder. GetElementById (" placeimg ");
Placeimg. SetAttribute (" SRC ", source);
Var placetext=placeholder. GetElementById (" placetext ");
Placetext. FirsChild. NodeValue=https://bbs.csdn.net/topics/this.getAttribute (" title ");
return false;
}
}

}
Wrote a js function is used to create an area at the bottom of the page, used to display a thumbnail images in a larger version of figure, at the time of clicking on a can put inside a thumbnail shows to this area,
Created earlier area shows the normal, but when clicking on a no effect, I take chorme devtools debugging found just skip the onclick function inside the for loop, don't know is what reason,

CodePudding user response:

InsertAfter (placeholder, images);
Var placeimg=placeholder. GetElementById (" placeimg ");
Your code is not finished paste? Himself wrote a insertAfter and getElementById method?

CodePudding user response:

It's not an error? Look at the console, a lot of mistakes.
if(! Document. The getElementById) return false;

CodePudding user response:

Yes, insertAfter function is written by yourself, getElementById is the method object, because the first half is normal operation, only in the inside of the for loop onclick function has been not when debugging function

CodePudding user response:

Dom elements not directly call getElementById method, var placeimg=placeholder. GetElementById (" placeimg "); This error?

CodePudding user response:

I changed the line no error because when debugging haven't into the onclick function
  • Related