addEventListener not working in IE8

前端 未结 9 1601
耶瑟儿~
耶瑟儿~ 2020-11-22 15:40

I have created a checkbox dynamically. I have used addEventListener to call a function on click of the checkbox, which works in Google Chrome and Firefox but <

9条回答
  •  北恋
    北恋 (楼主)
    2020-11-22 15:47

    if (document.addEventListener) {
        document.addEventListener("click", attachEvent, false);
    }
    else {
        document.attachEvent("onclick", attachEvent);
    }
    function attachEvent(ev) {
        var target = ev.target || ev.srcElement;
        // custom code
    }
    

提交回复
热议问题