<mce:script type="text/javascript"><!--
function show()
{
if(document.attachEvent)
alert("load");
}
//window.onload=show;
document.onload=alert("document.onload");
document.onload=show();
//document.attachEvent("onclick",show);
// --></mce:script>
<body >
<input type="button" value="button" id="btn">
<hr>
</body>
<mce:script type="text/javascript"><!--
//document.onload=show();
// --></mce:script>
<mce:script type="text/javascript"><!--
function show()
{
if(document.attachEvent)
alert("load");
}
//window.onload=show;
document.onload=alert("document.onload");
document.onload=show();
//document.attachEvent("onclick",show);
// --></mce:script>
<body >
<input type="button" value="button" id="btn">
<hr>
</body>
<mce:script type="text/javascript"><!--
//document.onload=show();
// --></mce:script>
总结:window.onload=函数名
document.onload=函数名()
document.attachEvent有效
document.attachEvent("onload",show); 是不会成功的
view plaincopy to clipboardprint?
<mce:script type="text/javascript"><!--
function $(id)
{
return document.getElementById(id);
}
function show()
{
alert($("btn").value);
if(document.attachEvent)
alert("load");
}
window.onload=show;
//document.onload=show();
// --></mce:script>
<body >
<input type="button" value="button" id="btn">
<hr>
</body>
<mce:script type="text/javascript"><!--
function $(id)
{
return document.getElementById(id);
}
function show()
{
alert($("btn").value);
if(document.attachEvent)
alert("load");
}
window.onload=show;
//document.onload=show();
// --></mce:script>
<body >
<input type="button" value="button" id="btn">
<hr>
</body>
在window.onload中getElementById有效
而在document.onload中无效.
**IE环境下