在一页页面中,同时出现了两个window.onload函数,发现第二个函数将会覆盖第一函数,第一个函数将会不起作用!
<
html
>
< head >
< script type ="text/javascript" language ="javascript" >
window.onload = function ()
{
alert( " 第一次调用 " );
}
</ script >
</ head >
< body >
< script type ="text/javascript" language ="javascript" >
window.onload = function ()
{
alert( " 第二次调用 " );
}
</ script >
</ body >
</ html >
< head >
< script type ="text/javascript" language ="javascript" >
window.onload = function ()
{
alert( " 第一次调用 " );
}
</ script >
</ head >
< body >
< script type ="text/javascript" language ="javascript" >
window.onload = function ()
{
alert( " 第二次调用 " );
}
</ script >
</ body >
</ html >
那么,怎么解决这个办法呢!
请看下面。
<
html
>
< head >
< script type ="text/javascript" language ="javascript" >
window.onload = function ()
{
alert( " 第一次调用 " );
}
</ script >
</ head >
< body >
< script type ="text/javascript" language ="javascript" >
function twofunction ()
{
alert( " 第二次调用 " );
}
window.attachEvent('onload',twofunction);
</ script >
</ body >
</ html >
< head >
< script type ="text/javascript" language ="javascript" >
window.onload = function ()
{
alert( " 第一次调用 " );
}
</ script >
</ head >
< body >
< script type ="text/javascript" language ="javascript" >
function twofunction ()
{
alert( " 第二次调用 " );
}
window.attachEvent('onload',twofunction);
</ script >
</ body >
</ html >