最后单表提交时的验证还得添加这么一个函数
在<form>里添加一个onsubmit的属性,JS添加一个用于表单验证的函数。函数错误,则return false,表单则不能被上传
<html>
<head>
<script>
function validate(){
var t1 = document.getElementById("t1");
var t2 = document.getElementById("t2");
if(t1.value =="" || t1.value.length<=6){
alert("t1 error");
return false;
}
if(t1.value =="" || t2.value.length<=10){
alert("t2 error");
return false;
}
alert("form submit success");
return true;
}
</script>
</head>
<body>
<form id="form1" name="form2" action="" onsubmit="return validate()" method="post">
t1 length must be larger than 6<input type="text" id="t1" name="t1">
t2 length must be larger than 10<input type="text" id="t2" name="t2">
<input type="submit" value="submit">
</form>
</body>
</html>