87,907
社区成员
发帖
与我相关
我的任务
分享
<script>
function testfun(){
alert(1);
}
if(document.all){
window.attachEvent("onload",testfun);
}else{
window.addEventListener("load",testfun(), false);
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> new document </title>
<meta name="generator" content="editplus" />
<meta name="author" content="Gao YiXiang" />
<meta name="email" content="yixianggao@126.com" />
<meta name="keywords" content="javascript dhtml dom" />
<meta name="description" content="I love web development." />
</head>
<body>
测试文本。
<SCRIPT FOR="window" EVENT="onload" LANGUAGE="JavaScript">
alert(1);
</SCRIPT>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> new document </title>
<meta name="generator" content="editplus" />
<meta name="author" content="Gao YiXiang" />
<meta name="email" content="yixianggao@126.com" />
<meta name="keywords" content="javascript dhtml dom" />
<meta name="description" content="I love web development." />
</head>
<body>
测试文本。
<SCRIPT FOR="window" EVENT="onload" LANGUAGE="JScript">
alert(1);
</SCRIPT>
</body>
</html>
onload Event
The browser loads applications, embedded objects, and images as soon as it encounters the applet, embed, and img objects during parsing. Consequently, the onload event for these objects occurs before the browser parses any subsequent objects. To ensure that an event handler receives the onload event for these objects, place the script object that defines the event handler before the object and use the onload attribute in the object to set the handler.
The onload attribute of the body object sets an onload event handler for the window. This technique of calling the window onload event through the body object is overridden by any other means of invoking the window onload event, provided the handlers are in the same script language.
<script>
function testfun(e){
alert(1);
}
if (document.body.addEventListener) {
window.addEventListener( "load", testfun, false );
}
else if (document.body.attachEvent) {
window.attachEvent( "onload", testfun );
}
</script>
function testfun(){
alert(1);
}
if(document.all){
window.attachEvent("onload",testfun);
}else{
window.addEventListener("load", testfun, false);
}