Display random image when page loads without utilizing onload in the body tag

后端 未结 9 734
逝去的感伤
逝去的感伤 2021-01-06 06:14

I\'m trying to create a fairly simple piece of JavaScript that displays a random image from an array each time the page loads. I need to figure out a way to get this runnin

9条回答
  •  隐瞒了意图╮
    2021-01-06 06:53

    Just don't put you javascript inside a function.

    if you take it out of the function it will run when the page loads.

    When it's in the function, it won't run unless called.

提交回复
热议问题