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