Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm trying to set an 'src' by calling a javascript function that returns the path like so:

<img src="getImagePath()" />

the function:

function getImagePath(){

     return "images/image1.png";

}

But it doesn't seem to work. Anything I'm missing? Thanks to anyone pointing me in the right direction.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
322 views
Welcome To Ask or Share your Answers For Others

1 Answer

The src attribute takes an URL, not JavaScript. You might want to try

<img src="pixel.gif" onload="this.onload=null; this.src=getImagePath();" />

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...