一段简单的JS代码:
1. test.html
<html>
<head>
<title>MyHtml.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="js/test.js" defer="defer"></script>
</head>
<body onload="test()">
This is my HTML page.
<br> </body>
</html>
<script type="text/javascript" defer="defer">
function test(){
Body.onload();
}
</script>
test.js:
Body = {
onload : function(){
alert(''hehe);
}
}
在火狐下执行没用问题,IE7下执行出错:Body.onload()未定义!
1. test.html
<html>
<head>
<title>MyHtml.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="js/test.js" defer="defer"></script>
</head>
<body onload="test()">
This is my HTML page.
<br> </body>
</html>
<script type="text/javascript" defer="defer">
function test(){
Body.onload();
}
</script>
test.js:
Body = {
onload : function(){
alert(''hehe);
}
}
在火狐下执行没用问题,IE7下执行出错:Body.onload()未定义!
onload : function(){
alert('hehe');
}
}
alert('hehe');