欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JavaScript中點(diǎn)擊事件的寫(xiě)法

 更新時(shí)間:2016年06月28日 11:05:05   作者:小碼農(nóng)雯  
這篇文章主要介紹了JavaScript中點(diǎn)擊事件的寫(xiě)法的相關(guān)資料,其中還給大家分享js觸發(fā)按鈕點(diǎn)擊功能的實(shí)現(xiàn),本文介紹的非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下
<button id="btn">click</button>
var btn=document.getElementById('btn');

第一種:

btn.onclick=function(){
alert('hello world');
}

消除事件:btn.onclick=null;//就不會(huì)彈出框了

第二種:

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觸發(fā)按鈕點(diǎn)擊事件

模擬JS觸發(fā)按鈕點(diǎn)擊功能

<html> 
  <head> 
    <title>usually function</title> 
  </head> 
  <script> 
function load(){ 
  //下面兩種方法效果是一樣的 
  document.getElementById("target").onclick(); 
  document.getElementById("target").click(); 
} 
function test(){ 
  alert("test"); 
} 
</script> 
  <body onload="load()"> 
    <button id="target" onclick="test()">test</button> 
  </body> 
<html>  

 備注:

btnObj.click()是真正地用程序去點(diǎn)擊按鈕,觸發(fā)了按鈕的onclick()事件

btnObj.onclick()只是簡(jiǎn)單地調(diào)用了btnObj的onclick所指向的方法,只是調(diào)用方法而已,并未觸發(fā)事件

相關(guān)文章

最新評(píng)論