這篇文章主要介紹了JavaScript中點(diǎn)擊事件的寫法的相關(guān)資料,其中還給大家分享js觸發(fā)按鈕點(diǎn)擊功能的實(shí)現(xiàn)。
var btn=document.getElementById('btn');第一種:
btn.onclick=function(){
alert('hello world');}
消除事件:btn.onclick=null;//就不會彈出框了
第二種:
btn.addEventListener('click',function(){alert('hello world')},false);
btn.addEventListener('click',function(){alert(this.id)},false);第三種:
function demo(){
alert('hello');
}
關(guān)鍵詞:



