我有一段Html,我有用戶點擊一個鏈接(刪除),然後頁面顯示'確認刪除'按鈕。當點擊確認刪除按鈕時,JavaScript執行Ajax調用來執行刪除操作。這在Chrome中非常適用,但不適用於Internet Explorer(v11)。爲什麼Javascript在IE中不起作用
在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;
};
});
嘗試'$(文件)''而不是$(文檔)'。一般來說JS是區分大小寫的。 – Sirko
對上述代碼進行一些小調試,並在您的問題中提供結果。 –
[在href ie 11中使用js時出錯]可能的重複(http://stackoverflow.com/questions/23077303/error-when-using-js-in-href-ie-11) –