demo.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script type="text/javascript">
document.getElementById("panel").οnclick=function(){
alert( "元素已经加载完毕 !");
}
/*执行错误*/
</script>
</head>
<body>
<div id="panel">click me.</div>
</body>
</html>
效果图:
demo2.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<div id="panel">click me.</div>
<script type="text/javascript">
document.getElementById("panel").οnclick=function(){
alert( "元素已经加载完毕 !");
}
/*正确执行*/
</script>
</body>
</html>
效果图:
demo3.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Panel</title>
<script type="text/javascript">
window.onload = function(){
document.getElementById("panel").οnclick=function(){
alert( "元素已经加载完毕 !");
}
}
</script>
</head>
<body>
<div id="panel">click me.</div>
</body>
</html>
效果图:
demo4.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Panel</title>
<script src="js/jquery-1.10.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
document.getElementById("panel").οnclick=function(){
alert( "元素已经加载完毕 !");
}
})
</script>
</head>
<body>
<div id="panel">click me.</div>
</body>
</html>
效果图:
demo5.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script type="text/javascript">
function one(){
alert("one");
}
function two(){
alert("two");
}
window.onload = one ;
window.onload = two ;
</script>
</head>
<body>
</body>
</html>
效果图:
demo6.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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script src="js/jquery-1.10.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
function one(){
alert("one");
}
function two(){
alert("two");
}
$(document).ready(function(){
one();
})
$(document).ready(function(){
two();
})
</script>
</head>
<body>
</body>
</html>
效果图: