当页面载入时,会执行位于 body 部分的 JavaScript。
当被调用时,位于 head 部分的 JavaScript 才会被执行。
<
html
>
< head >
</ head >
< body >
< script type = " text/javascript " >
document.write( " 该消息在页面加载时输出。 " )
</ script >
</ body >
</ html >
< head >
</ head >
< body >
< script type = " text/javascript " >
document.write( " 该消息在页面加载时输出。 " )
</ script >
</ body >
</ html >
当页面被调用时执行,如:
<
html
>
< head >
< script type = " text/javascript " >
function message()
{
alert( " 该提示框是通过 onload 事件调用的。 " )
}
</ script >
</ head >
< body onload = " message() " >
</ body >
</ html >
< head >
< script type = " text/javascript " >
function message()
{
alert( " 该提示框是通过 onload 事件调用的。 " )
}
</ script >
</ head >
< body onload = " message() " >
</ body >
</ html >