开发者

Internet Explorer 8 choking on function call (JavaScript)

I have this line in a function handling click events. It works in Firefox, but not IE8 and I don't see how to create a workaround. (Jquery answers welcome!).

n.b I cannot use the this keyword as in context it will be useless.

elementsList[i].previousSibling.lastChild.addEventListener("click", (f开发者_如何转开发unction(el){
            return function(){
                 toggle(el)
             };
       })(elementsList[i]),false); 

edit

To answer comments

elementsList is an array containing various nodes such as divs and p tags.


Internet Explorer does not support addEventListener before version 9.

Use a library to iron out the differences, since you mentioned jQuery, use bind


jQuery:

$( elementsList[i] ).prev().last().click(function() {
    toggle( this );
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜