** onload静态事件**
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>事件</title>
</head>
<body onload="alert('onload事件执行')">
<div></div>
</body>
</html>
** onload要执行多个静态事件**
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>事件</title>
<script>
function onloadFun(){
alert('onload事件执行');
}
</script>
</head>
<body onload="onloadFun()">
<div></div>
</body>
</html>
** onload动态事件注册**
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>onload动态注册</title>
<script>
window.onload=function () {
alert("onload动态事件注册")
}
</script>
</head>
<body>
</body>
</html>
** onclick静态单击事件**
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>onclick静态注册</title>
<script>
function onclickFun() {
alert("单击静态注册")
}
</script>
</head>
<body>
<button onclick="onclickFun()">按钮1</button>
</body>
</html>
<br /> ** onclick动态单击注册**
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>onclick动态注册</title>
<script>
window.onclick=function () {
//先通过ID获取标签对象
var obj=document.getElementById("001");
//再通过对象.事件名=function(){}
obj.onclick=function () {
alert("动态单击事件注册");
}
}
</script>
</head>
<body>
<button id="001">按钮1</button>
</body>
</html>