<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h1 id="one">第一种写法/h1>
<h2 onClick="printFn()"> 第二种写法</h2>
<h3 onclick="javascript:alert('第三种写法')">第三种写法</h3>
<h4 id="two">第四中写法</h4>
</body>
<script>
document.getElementById("one").addEventListener("click", function () {
console.log("第一种写法")
}, false)
function printFn() {
console.log("第二种写法")
}
var two =document.getElementById("two");//通过id找/class不行和第一种类似
two.onclick=function(){
console.log("这是第四种写法")
}
</script>
</html>