当JavaScript离开页面时可以进行的操作
window.onbeforeunload = function()
{
var email = document.getElementById("email").value;
if(!email) return "确定";
}
全部代码如下:
<%@page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE html> //html5语言头文件
<head>
<title></title>
<script type="text/javascript">
window.onbeforeunload = function() //主要方法
{
var email = document.getElementById("email").value; //获取页面输入框的value值
if(!email) return "确定"; //如果Email是空,是null或者undinefind
}
</script>
</head>
<body>
<input type="text" id="email" placeholder="请输入您的邮箱"/>
</body>
</html>
时间: 2024-10-05 05:00:48