InternetExplorer8被函数调用(JavaScript)阻塞

Internet Explorer 8 choking on function call (JavaScript)

本文关键字:阻塞 JavaScript 函数调用 InternetExplorer8      更新时间:2023-09-26

我在一个处理点击事件的函数中有这一行。它在Firefox中有效,但在IE8中无效,我不知道如何创建变通方法。(欢迎Jquery回答!(。

n.b我不能使用this关键字,因为在上下文中它是无用的。

elementsList[i].previousSibling.lastChild.addEventListener("click", (function(el){
            return function(){
                 toggle(el)
             };
       })(elementsList[i]),false); 

编辑

回答意见

elementsList是一个数组,包含各种节点,如div和p标记。

Internet Explorer在版本9之前不支持addEventListener。

使用库来消除差异,因为您提到了jQuery,所以使用bind

jQuery:

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