我有一段Html,我让用户点击一个链接(删除),然后页面显示一个'确认删除'按钮。当'确认删除'单击按钮,JavaScript执行Ajax调用以执行删除。这适用于Chrome,但不适用于Internet Explorer(v11)。
在Chrome中调试时,我可以看到调用的JavaScript,但不能在Internet Explorer中看到。
该应用程序是MVP。这是呈现的HTML:
<td>
<a href="/project/edit">Edit</a> |
<a href="/project/details">Details</a> |
<a class="delete-link" href="javascript:void(0);">Delete</a>
<div class="btn btn-primary delete-confirm" style="display: none;" data-delete-action="_submissionfiledelete" data-delete-controller="project" data-delete-id="b59fa83e-14a8-e511-8172-00215e466552">Confirm Delete</div>
</td>
这是javascript:
$(function () {
$(Document).on("click",".delete-link",function (event) {
var deleteLink = $(this);
deleteLink.hide();
var confirmButton = deleteLink.siblings(".delete-confirm");
confirmButton.show();
var cancelDelete = function () {
removeEvents();
showDeleteLink();
};
var deleteItem = function () {
removeEvents();
confirmButton.hide();
var url = '/' + confirmButton.attr('data-delete-controller') + '/' + confirmButton.attr('data-delete-action') + '/' + confirmButton.attr('data-delete-id');
$.post(
url,
AddAntiForgeryToken({ id: confirmButton.attr('data-delete-id') }))
.done(function () {
var parentRow = deleteLink.closest(".removable-row"); //"tr:first, li:first");
parentRow.fadeOut('fast', function() {
parentRow.remove();
});
}).fail(function (data) {
var bpData = data;
});
return false;
};
var removeEvents = function () {
confirmButton.off("click", deleteItem);
$(document).on("click", cancelDelete);
$(document).off("keypress", onKeyPress);
};
var showDeleteLink = function () {
confirmButton.hide();
deleteLink.show();
};
var onKeyPress = function (e) {
//Cancel if escape key pressed
if (e.which == 27) {
cancelDelete();
}
};
confirmButton.on("click", deleteItem);
$(document).on("click", cancelDelete);
$(document).on("keypress", onKeyPress);
return false;
});
AddAntiForgeryToken = function (data) {
data.__RequestVerificationToken = $('input[name=__RequestVerificationToken]').val();
return data;
};
});
答案 0 :(得分:1)
void将覆盖IE中的onclick事件
更改此行:
<a class="delete-link" href="javascript:void(0);">Delete</a>
到此:
<a class="delete-link" href="#">Delete</a>
您可以尝试强制使用边缘模式:
<meta http-equiv="X-UA-Compatible" content="IE=edge" />