我的代码实际上在 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);
}
});
});
更新:如果我将在 IE 中不起作用的代码放在 AJAx-Request 之外,它正在工作:
$$('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){
}
但是在 onLoading-function 里面却不是,为什么?!