添加事件就是绑定事件:
第一种:直接在标签里添加事件=方法名()
<body>
<span onclick="t()" id ="time">添加事件</span>
<script>
function t(){
console.log("事件")
}
</script>
<body>
第二种:通过addEventListener方法添加事件和方法 方法名()
<body>
<span id ="time">添加事件</span>
<script>
document.getElementById("time").addEventListener("click", function t(){console.log("事件")});
</script>
<body>
第三种:直接添加.事件=方法 方法名()
<body>
<span id ="time">添加事件</span>
<script>
document.getElementById("time").onclick=function t(){console.log("事件")};
</script>
<body>