我正在asp.net中开发Web应用程序。我的要求是在每个按钮点击事件(如插入,更新和删除按钮)上显示确认消息。我正在使用jQuery消息框通过应用程序成功插入,更新和删除。
let domainName = NSBundle.mainBundle().bundleIdentifier!
NSUserDefaults.standardUserDefaults().removePersistentDomainForName(domainName)
调用按钮点击事件
function MessageBox(Title, InnerText) {
try {
var dialog = $('<p class="messagebox">' + InnerText + '</p>').dialog({
title: Title,
width: "240",
modal: true,
buttons: {
"OK": function () {
dialog.dialog('close');
}
}
});
}
catch (e) {
MessageBox('Tracker Alert', e);
}
}
然后,如何使用与上述功能相同的jQuery消息框在按钮点击事件上显示确认消息?
答案 0 :(得分:0)
<script type="text/javascript">
$(window).on('mouseover', (function () {
window.onbeforeunload = ConfirmLeave;
}));
$(window).on('mouseout', (function () {
window.onbeforeunload = ConfirmLeave;
}));
function ConfirmLeave() {
return "";
}
var prevKey = "";
$(document).keydown(function (e) {
if (e.key == "F5") {
window.onbeforeunload = ConfirmLeave;
}
else if (e.key.toUpperCase() == "W" && prevKey == "CONTROL") {
window.onbeforeunload = ConfirmLeave;
}
else if (e.key.toUpperCase() == "R" && prevKey == "CONTROL") {
window.onbeforeunload = ConfirmLeave;
}
else if (e.key.toUpperCase() == "F4" && (prevKey == "ALT" || prevKey == "CONTROL")) {
window.onbeforeunload = ConfirmLeave;
}
prevKey = e.key.toUpperCase();
});
</script>