<body>
<button onclick="s1()">Button</button>
<button id="btn2">Button2</button>
<button id="btn3">Button3</button>
</body>
<script>
//第一种
function s1(){
console.log(1);
}
//第二种
document.getElementById("btn2").onclick = function () {
console.log(2);
};
document.getElementById("btn2").onclick = function () {
console.log(22);
};
//第三种
var btn3 = document.getElementById("btn3");
btn3.addEventListener("click",function(){
console.log(3);
},false);
btn3.addEventListener("click",function(){
console.log(33);
},false);
</script>
js中三种点击事件的触发
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.