<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<title>页面改变提示</title>
<script>
var isChanged = false;
function checkChanges() {
if (isChanged) {
return "您有未保存的更改,确定要离开吗?";
} else {
return null;
}
}
window.addEventListener("beforeunload", function (event) {
var message = checkChanges();
if (message) {
event.preventDefault();
event.returnValue = message;
}
});
function onInputChange() {
isChanged = true;
}
</script>
</head>
<body>
<input type="text" oninput="onInputChange()" placeholder="请输入内容">
</body>
</html>
修改后,离开页面时提醒保存
最新推荐文章于 2024-08-24 11:46:12 发布