JavaScript中的onunload事件有什么用?
当您卸载(或刷新)页面时,将触发unload事件。您可以尝试运行以下代码,以了解如何在JavaScript中实现onunload 事件。
示例
<!DOCTYPE html>
<html>
<body onunload="newFunc()">
<p>Close the page and see what happens!</p>
<p>This event may give unexpected results.</p>
<script>
function newFunc() {
alert("谢谢!");
}
</script>
</body>
</html>