私は次のJavaScriptを持っています
編集:変更の割り当てが含まれています保存されました
var changesSaved = true;
$(document).ready(function () {
$(".applyChanges").click(function (e) {
e.preventDefault();
var id = (this).id;
var dayofweek = document.getElementById("dayofweek" + id).value;
var hour = document.getElementById("hour" + id).value;
var duration = document.getElementById("duration" + id).value;
$.ajax({
url: '@Url.Action("ApplyChanges")',
type: 'POST',
data: {
id: id,
dayofweek: dayofweek,
hour: hour,
duration: duration
},
success: function (data) {
$('#Calendar').fullCalendar('refetchEvents')
$('#Calendar2').fullCalendar('refetchEvents')
changesSaved = false;
}
});
});
});
window.onbeforeunload = function () {
if (changesSaved == true) {
return true;
} else {
return ("You havent saved your changes. Are you sure you want to leave the page?")
}
}
ただし、何changesSaved
が設定されているかに関係なく、メッセージはプロンプト表示されます。
実際に私が実際に得るものは次のとおりです。
または、changesSaved
がfalseに設定されている場合は、代わりにfalseと表示されます。
これはできませんか?