How does the location of a script tag in a page affect a JavaScript function that is defined in it?

后端 未结 9 1257
死守一世寂寞
死守一世寂寞 2020-11-29 04:27

I read that you should define your JavaScript functions in the tag, but how does the location of the

9条回答
  •  Happy的楠姐
    2020-11-29 04:48

    If you pull Javascripts in through XMLHttpRequest, like Diodeus said, it probably won't work. In my case, there was no error, the browser just ignores the new script(s).

    I ended up using this, not terribly elegant but works for me so far:

    http://zeta-puppis.com/2006/03/07/javascript-script-execution-in-innerhtml-the-revenge/

    How to use execJS: http://zeta-puppis.com/2006/02/23/javascript-script-execution-in-innerhtml/

    Note: Watch out for < in this line: for(var i=0;i

提交回复
热议问题