Javascript $$(';a.deleteButton';)。调用(';观察';,';单击';,函数(e)在Internet Explorer中不工作

Javascript $$(';a.deleteButton';)。调用(';观察';,';单击';,函数(e)在Internet Explorer中不工作,javascript,internet-explorer,prototypejs,Javascript,Internet Explorer,Prototypejs,我的代码实际上在chrome中运行得很好,但在IE中测试失败:/ e、 element().hide()和e.element().insert()不起作用。Ajax.Request()在这两种浏览器中都能正常工作。 知道怎么修理吗 $$('a.deleteButton').invoke('observe', 'click', function(e) { var commentID = parseInt(this.readAttribute('data-commentid'

我的代码实际上在chrome中运行得很好,但在IE中测试失败:/ e、 element().hide()和e.element().insert()不起作用。Ajax.Request()在这两种浏览器中都能正常工作。 知道怎么修理吗

$$('a.deleteButton').invoke('observe', 'click', function(e) {
            var commentID = parseInt(this.readAttribute('data-commentid'));
            e.stop();
            new Ajax.Request('index.php?action=CNewsComment',
                    {
                        method: 'POST',
                        parameters: {entryID: commentID, cNewsAction: 'delete'},
                        onSuccess: function(transport){
                            new Effect.toggle('commentID' + commentID, 'Appear', {duration:0.5});
                            var count = parseInt($('commentsCount').innerHTML.stripTags());
                            $('commentsCount').innerHTML = count-1;
                        },
                        onLoading: function(transport){
                            e.element().hide(); //not working in IE but in Chrome

                            if ($('deleteLoading' + commentID)) {
                                $('deleteLoading' + commentID).show();
                            }
                            else {
                                e.element().up().insert ({ 
                                    'before'  : '<img id="deleteLoading' + commentID + '" src="' + RELATIVE_WCF_DIR + 'images/cNewsSpinnerS.gif" alt="" />'
                                });
                            }
                        },
                        onFailure: function(transport){ 
                            e.element().show();                         
                            $('deleteLoading' + commentID).hide();                          
                            alert("An error occurred: " + transport.status + ' - ' + transport.statusText);
                        }
            });
    });
$$('a.deleteButton')。调用('observe','click',函数(e){
var commentID=parseInt(this.readAttribute('data-commentID');
e、 停止();
新的Ajax.Request('index.php?action=cnewscompent',
{
方法:“POST”,
参数:{entryID:commentID,cNewsAction:'delete'},
onSuccess:功能(传输){
new Effect.toggle('commentID'+commentID,'出现',{duration:0.5});
var count=parseInt($('commentscont').innerHTML.stripTags();
$('CommentScont')。innerHTML=count-1;
},
加载:功能(传输){
e、 element().hide();//不在IE中工作,但在Chrome中工作
如果($('deleteLoading'+commentID)){
$('deleteLoading'+commentID).show();
}
否则{
e、 元素().up().insert({
“之前”:”
});
}
},
onFailure:函数(传输){
e、 元素().show();
$('deleteLoading'+commentID).hide();
警报(“出现错误:“+transport.status+”-“+transport.statusText”);
}
});
});
更新: 如果我将IE中不起作用的代码放在AJAx请求之外,它就起作用了:

$$('a.deleteButton').invoke('observe', 'click', function(event) {
            event.stop();
            // IE PART START
            event.element().hide();
            if ($('deleteLoading' + commentID)) {
                $('deleteLoading' + commentID).show();
            }
            else {
                event.element().up().insert ({ 
                'before'  : '<img id="deleteLoading' + commentID + '" src="' + RELATIVE_WCF_DIR + 'images/cNewsSpinnerS.gif" alt="" />'
                });
            }
            // IE PART END
            new Ajax.Request('index.php?action=CNewsComment',
                    {
                        method: 'POST',
                        parameters: {entryID: commentID, cNewsAction: 'delete'},
                        onLoading: function(transport){
                        }
$$('a.deleteButton')。调用('observe','click',函数(事件){
事件停止();
//部分开始
event.element().hide();
如果($('deleteLoading'+commentID)){
$('deleteLoading'+commentID).show();
}
否则{
event.element().up().insert({
“之前”:”
});
}
//部分结束
新的Ajax.Request('index.php?action=cnewscompent',
{
方法:“POST”,
参数:{entryID:commentID,cNewsAction:'delete'},
加载:功能(传输){
}

但是在onload函数中它不是,为什么?!

我只知道一点原型。但是你如何调试以检查“e”是否是你想要使用的元素。有时我会遇到这种问题。

$$('a.deleteButton')。调用('observe','click',function(e){
$$('a.deleteButton').invoke('observe', 'click', function(e) {
        var commentID = parseInt(this.readAttribute('data-commentid'));
        e.stop();
        new Ajax.Request('index.php?action=CNewsComment',
                {
                    method: 'POST',
                    parameters: {entryID: commentID, cNewsAction: 'delete'},
                    onSuccess: function(transport){
                        new Effect.toggle('commentID' + commentID, 'Appear', {duration:0.5});
                        var count = parseInt($('commentsCount').innerHTML.stripTags());
                        $('commentsCount').innerHTML = count-1;
                    },
                    onLoading: (function(transport, e){
                        e.element().hide(); //not working in IE but in Chrome

                        if ($('deleteLoading' + commentID)) {
                            $('deleteLoading' + commentID).show();
                        }
                        else {
                            e.element().up().insert ({ 
                                'before'  : '<img id="deleteLoading' + commentID + '" src="' + RELATIVE_WCF_DIR + 'images/cNewsSpinnerS.gif" alt="" />'
                            });
                        }
                    }).bindAsEventListener(this),
                    onFailure: function(transport){ 
                        e.element().show();                         
                        $('deleteLoading' + commentID).hide();                          
                        alert("An error occurred: " + transport.status + ' - ' + transport.statusText);
                    }
        });
});
var commentID=parseInt(this.readAttribute('data-commentID'); e、 停止(); 新的Ajax.Request('index.php?action=cnewscompent', { 方法:“POST”, 参数:{entryID:commentID,cNewsAction:'delete'}, onSuccess:功能(传输){ new Effect.toggle('commentID'+commentID,'出现',{duration:0.5}); var count=parseInt($('commentscont').innerHTML.stripTags(); $('CommentScont')。innerHTML=count-1; }, 加载:(功能(传输,e){ e、 element().hide();//不在IE中工作,但在Chrome中工作 如果($('deleteLoading'+commentID)){ $('deleteLoading'+commentID).show(); } 否则{ e、 元素().up().insert({ “之前”:” }); } }).bindAsEventListener(本文件), onFailure:函数(传输){ e、 元素().show(); $('deleteLoading'+commentID).hide(); 警报(“出现错误:“+transport.status+”-“+transport.statusText”); } }); });
试试这个:

    $$('a.deleteButton').invoke('observe', 'click', function(e) {
        var element = e.element();
        var commentID = parseInt(this.readAttribute('data-commentid'));
        e.stop();
        new Ajax.Request('index.php?action=CNewsComment', {
            method: 'POST',
            parameters: {entryID: commentID, cNewsAction: 'delete'},
            onSuccess: function(transport) {
                new Effect.toggle('commentID' + commentID, 'Appear', {duration:0.5});
                var count = parseInt($('commentsCount').innerHTML.stripTags());
                $('commentsCount').innerHTML = count-1;
            },
            onLoading: function(transport) {
                element.hide(); // not working in IE but in Chrome

                var delId = 'deleteLoading' + commentID;
                if ($(delId)) {
                    $(delId).show();
                } else {
                    element.up().insert({ 
                        'before': '<img id="' + delId + '" src="' + RELATIVE_WCF_DIR + 'images/cNewsSpinnerS.gif" alt="" />'
                    });
                }
            },
            onFailure: function(transport) { 
                element.show();                         
                $('deleteLoading' + commentID).hide();                          
                alert("An error occurred: " + transport.status + ' - ' + transport.statusText);
            }
        });
    });

注意:您使用哪个IE版本?较旧的IE只有一个全局事件对象
窗口。事件
,在异步回调时,您的
e
即使在关闭状态下也可能不会指向您原来的点击事件,而是指向在调用
onload
之前触发的另一个事件。

只是检查IE是否跳入正在加载状态-确实如此。您将如何调试它?IE不会给出任何javascript错误。我尝试向您伸出援手。我感到很抱歉,这没有帮助。但您太吝啬了。如果您不需要帮助,为什么要寻求帮助。我也没有否决,但这更适合作为一个评论,而不是回答。您是否可以去掉这个在IE中不工作但在其他浏览器中工作的代码最少?或者创建一个工作的小提琴?刚刚更新了我的问题Protoaculous.1.8.2.min.js,它是prototype 1.6.0.3用最新的prototype版本测试,仍然不工作。
            onLoading: function(element, transport) {
                element.hide(); // not working in IE but in Chrome

                var delId = 'deleteLoading' + commentID;
                if ($(delId)) {
                    $(delId).show();
                } else {
                    element.up().insert({ 
                        'before': '<img id="' + delId + '" src="' + RELATIVE_WCF_DIR + 'images/cNewsSpinnerS.gif" alt="" />'
                    });
                }
            }.curry(element),