https://www.jqueryscript.net/form/alert-form-changed-dirty.html
$(function() {
$("#input-form").dirty({
preventLeaving: true,
leavingMessage: 'NO SAVE',
onDirty: function(){
alert("フォームが変更されています。ページを離れますか?")
}
});
});
他にも便利なメソッドがあります
// detects if a form has been modified
// returns true or false
$("#form").dirty("isDirty");
// detects if a form is Clean
// returns true or false
$("#form").dirty("isClean");
// refreshes events
$("#form").dirty("refreshEvents");
// resets the form
$("#form").dirty("resetForm");
// sets the state to Clean
$("#form").dirty("setAsClean");
// shows modified form fields
$("#form").dirty("showDirtyFields");