0
我有下面的代碼來處理未保存的表單數據的情況下,以提示用戶但這種代碼也顯示在點擊時發出警報提交按鈕window.onbeforeunload警報提交
$(document).ready(function() {
var _isDirty = false;
$(":input").live("change", function() {
_isDirty = true;
});
$(':[type=submit]').live('click', function() {
_isDirty = false;
});
window.onbeforeunload = function() {
if (_isDirty) {
return 'You have made changes to data on this page. If you navigate away from this page without first saving your data, the changes will be lost.';
}
else {
return null;
}
}
}
獲取事件並使用preventDefault – 2011-06-08 10:30:44
您可以檢查代碼_isDirty = false是否實際執行? – Kangkan 2011-06-08 10:31:45