系统可能不会保存你所做的修改 onbeforeunload

网上找了好多实现这个的方法,说的还是不明白。害得我(我自己的原因)以为是需要在服务器环境下才能跑通 window.onbeforeunload; 后来猜想是不是函数返回值发生变化就会触发,于是对了。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
<body>
<input type="text" id = 'input' value = 'kkk'>
</body>
<script>

window.onbeforeunload = function() { 
    return $('#input').val()
}
</script>
</html>

猜你喜欢

转载自www.cnblogs.com/aiyr/p/9092811.html
今日推荐