Alternative to <body onload=“init ();”>

前端 未结 5 1274
Happy的楠姐
Happy的楠姐 2021-02-04 04:51

I\'m trying to fix an old script written for me. I need it to run without . I\'d like to run the function from inside the script wit

5条回答
  •  遇见更好的自我
    2021-02-04 05:28

    best option is to just put the call to init() at the bottom of the page:

    
    
    
    ...
    
    
    
    .... page content here ...
    
    
    
    

    By placing it at the bottom like that, you'll be sure that it runs as pretty much the very last thing on the page. However, note that it's not as reliable as using the onload option in the body tag, or jquery's $('document').ready() or mootool's window.addEvent('domready', ...).

提交回复
热议问题