我需要幫助。如果用戶離開頁面,並且表單已填寫或至少填寫了表單中的某些字段,我想要顯示確認提醒。我有以下代碼在Chrome中運行,但不能在Firefox中運行。即使表單域爲空,也會顯示警報。如果填寫表格,請在離開頁面時確認提醒
以下是我的代碼,
$(window).bind('beforeunload', function() {
return ''; //Are you sure you want to leave?';
});
所以我需要幫助,所以我可以在Firefox中產生警覺,並在形式完全或部分填充其他所有瀏覽器,但是當形式是空的不會產生任何警報。我試圖使用視圖狀態。檢查是否視圖狀態的值是不同的,那麼產生的警報,但它不工作,我希望
另一段代碼我想是
window.onbeforeunload = function (e) {
var message = "Your confirmation message goes here.",
e = e || window.event;
// For IE and Firefox
if (e) {
e.returnValue = message;
}
// For Safari
return message;
};
但上面的代碼並不檢查表單是否被填充。我想提醒當窗體部分或完全填充
@ketan我添加了一些代碼 – user4545762 2015-02-10 04:46:36