window.onload :页面加载完毕之后才会触发
eg:外部调用.js文件实现的点击事件
代码:
HTML:
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><script src="js/index.js"></script> <!-- 引入index.js文件 --></head><body><p id="p">hello world</p></body>
index.js:
window.onload = function(){var p=document.getElementById("p")p.onclick = function(){console.log("hello world")}}
