JavaScript中点击事件的写法
<button id="btn">click</button>
var ElementById('btn');
第⼀种:
alert('hello world');
}
消除事件:lick=null;//就不会弹出框了js调用方法的三种写法
第⼆种:
btn.addEventListener('click',function(){alert('hello world')},false);
btn.addEventListener('click',function(){alert(this.id)},false);
第三种:
function demo(){
  alert('hello');
}
<button id="btn" onclick="demo()">click</button>
下⾯给⼤家介绍js触发按钮点击事件
模拟JS触发按钮点击功能
<html>
<head>
<title>usually function</title>
</head>
<script>
function load(){
//下⾯两种⽅法效果是⼀样的
}
function test(){
alert("test");
}
</script>
<body onload="load()">
<button id="target" onclick="test()">test</button>
</body>
<html>
备注:
btnObj.click()是真正地⽤程序去点击按钮,触发了按钮的onclick()事件