给元素绑定事件的方式

方式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);
        }
原文地址:https://www.cnblogs.com/sunhk/p/4756960.html