js code in the <head> on the difference between the rear and <body> later

javascript code written in the <head> which:

Since a web page body (body) at this time is not yet loaded, so here is suitable to put some custom function is not executed immediately, immediate execution of the sentence is likely to be wrong (depending on your browser may be)

javascript code written in the <body> which:

Here you can put the function can also put statements executed immediately, but if you need to and interact with page elements (such as access to the value of a label or a label assignment), Javascript code is sure to label behind

javascript code written in the <body> following:

This time the entire page has loaded, so here is the most suitable place commands you want executed immediately, while custom function and the like are not suitable.

Guess you like

Origin www.cnblogs.com/linwenbin/p/11711448.html