attachEvent 방법 JS Function 호출

4952 단어 js
  HTML     UI   。
  ,               ,     ?
<input type="button" id="theBtn" value="  " onclick="alert('     ');" />
   ,      ,                  。
attachEvent        , :
<input type="button" id="theBtn" value="  " />
var theBtn = document.getElementById("theBtn");  //  ID theBtn   
theBtn.attachEvent("onclick", buttonClicked);   //       
function buttonClicked(e){  alert("     ");  }  //    
attachEvent  :
attachEvent(    ,     );
P.S.: Firefox ,      addEventListener(    ,     ,     );
    HTML             ,      HTML   JS   ,        。

Firefox  addEventListener  

if (window.addEventListener) {
window.addEventListener('DOMContentLoaded', handler, false); //firefox
window.addEventListener('load', handler, false);
} else if (window.attachEvent) {
 window.attachEvent('onload', handler); //IE
}

http://cache.baidu.com/c?m=9d78d513d99017f90fa9c3224b488c275f03dc347cc0d0642288cd15c0324f060738ece161645213d2b6617a59e71909b2b17d6537747bf1cc83df5dddccc3757095776a2d499b4417d912adc8&p=8970c54ad5c54add0aafc771070089&user=baidu&fm=sc&query=addEventListener+onload&qid=c7edbbe426f9d282&p1=1#baidusnap0

좋은 웹페이지 즐겨찾기