<!DOCTYPE html><html lang="en"><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></head><body><p id="p">hello world</p></body></html>
页面加载完毕之后才会触发
/* 页面加载完毕之后才会触发 */
window.onload = function () {
    var p = document.getElementById("p");
    p.onclick = function () {
        console.log("hello world")
    }
}
                    