addEventListener not working in IE8

前端 未结 9 1599
耶瑟儿~
耶瑟儿~ 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 16:07

    This is also simple crossbrowser solution:

    var addEvent =  window.attachEvent||window.addEventListener;
    var event = window.attachEvent ? 'onclick' : 'click';
    addEvent(event, function(){
        alert('Hello!')
    });
    

    Instead of 'click' can be any event of course.

提交回复
热议问题