<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
</head>
<!--load事件的使用,只有在整个页面加载完成后才会执行-->
<body onload="say()">
<script type="text/javascript">
/*
* javascript中的代码会顺序执行
*
* document.getElementById("mybtn").onclick=function(){
alert("test....");
}
*/
say=function(){
document.getElementById("mybtn").onclick=function(){
alert("load....");
}
}
</script>
<input type="button" value="hello" id="mybtn" />
</body>
</html>
![](https://img2024.cnblogs.com/blog/35695/202408/35695-20240826070647288-243310440.jpg)