kk Blog —— 通用基础

date [-d @int|str] [+%s|"+%F %T"]

页面内容已修改,您确定要离开?

html

1
2
3
4
<input style='display:none' name='beforeunload' id='beforeunload' value='0'>

<button id='{$idpre}_edit' type='button' class=submit onclick=enable_all()>编辑</button>
<input id='{$addidpre}_submit' class='submit' type='submit' value='提交' onclick=submit_it()>

js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
function enable_all() {
	var b = document.getElementById('beforeunload');
	if (b !== null)
		b.value = 2;
}

function submit_it() {
	var b = document.getElementById('beforeunload');
	if (b !== null)
		b.value = 1;
}

window.addEventListener("beforeunload", function(e) {
	var val = document.getElementById('beforeunload').value;
	if (val > 1) {
		var confirmationMessage = "您是否要离开 - 您输入的数据可能不会被保存。";
		(e || window.event).returnValue = confirmationMessage; // Gecko and Trident
		return confirmationMessage; // Gecko and WebKit});
	}
});