使用onsubmit函数,对表单中的数据进行验证。
<!DOCTYPE html>
<html>
<head>
<title>form.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
<script language="javascript">
function check(){
if(document.test.name.value==""){
alert("name不能为空");
return false;
}
return true;
}
</script>
</head>
<body>
<form action="1.html" name="test" οnsubmit="return check()">
<input type="text" name="name" />
<input type="submit" value="ok" />
</form>
</body>
</html>