对象.addEventListener(事件名称,事件处理函数,布尔值)事件监听
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<button id="mybtn">先点这里</button>
<button id="myBtn">再点这里</button>
<!-- <p id="demo"></p> -->
<script>
// 对象.addEventListener(事件名称,事件处理函数,布尔值)事件监听
var x=document.getElementById("mybtn");
x.addEventListener("click",myfunction);
var y=document.getElementById("myBtn");
y.addEventListener("click",secondfunction,false);
function myfunction(){
console.log("我爱你");
}
function secondfunction(){
console.log("骗你的!");
}
/* document.getElementById("mybtn").addEventListener("click",helloword)
function helloword(){
document.getElementById("demo").innerText+="helloword……";
} */
</script>
</body>
</html>