<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>表单验证</title>
</head>
<body>
<form name="myForm" action="xxxx">
<input type="text" id="t1" value="" />
<input type="text" id="t2" value="" />
<input type="radio" name="name1" id="name1" value="" />
<input type="radio" name="name2" id="name2" value="" />
<input type="button" value="submit" onclick="valid();">
</form>
<script type="text/javascript">
function valid() {
if (document.getElementById("t1").value == "") {
alert("t1不能为空");
return;
}
if (document.getElementById("t2").value == "") {
alert("t2不能为空");
return;
}
if (document.getElementById("name1").value == "") {
alert("name1不能为空");
return;
}
if (document.getElementById("name1").value == "") {
alert("name2不能为空");
return;
}
document.forms["myForm"].submit();
}
</script>
</body>
</html>
posted on 2017-11-15 16:03  FAIRY_TALE  阅读(142)  评论(0编辑  收藏  举报