<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>空表单时弹窗警告</title>
<script>
function validateForm(){
var x = document.forms["myForm"]["name"].value;
if(x == "" || x == null){
alert("名字不能为空");
return false;
}
}
</script>
</head>
<body>
<form name="myForm" action="hello.html" onsubmit="return validateForm()" method="get">
name:<input type="text" name="name" />
<input type="submit" value="提交" />
</form>
</body>
</html>
为空时:不为空时: