addEventListener not working in IE8

前端 未结 9 1597
耶瑟儿~
耶瑟儿~ 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:05

    Try:

    if (_checkbox.addEventListener) {
        _checkbox.addEventListener("click", setCheckedValues, false);
    }
    else {
        _checkbox.attachEvent("onclick", setCheckedValues);
    }
    

    Update:: For Internet Explorer versions prior to IE9, attachEvent method should be used to register the specified listener to the EventTarget it is called on, for others addEventListener should be used.

提交回复
热议问题