给元素绑定事件的方式

方式1(已解决兼容性):

        if(window.attachEvent){
            window.document.body.attachEvent("onclick", test);
        }else if(window.addEventListener) {
            window.document.body.addEventListener("click", test, false);
        }

方法2:

window.document.body.onclick = test;

test方法:

       function test(){
            alert(11);
        }

 

posted @ 2015-08-25 11:31  sunhaikuo  阅读(171)  评论(0编辑  收藏  举报