我有jsp页面-
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
</head>
<body>
<legend>Create new customer</legend>
<script Language="JavaScript">
function checkForm() {
alert("YOU ARE IN checkForm FUNCTION !");
return (false);
}
</script>
<form action="CreateCustomerServlet" method="GET" onsubmit="checkForm">
// form fields ...
<input type="submit" value="Create customer" />
</form>
</body>
</html>
当我在服务器上运行此页面并按
submit
按钮时,我看到它忽略了checkForm
并且不输入他,而是直接转到CreateCustomerServlet
。我的目标是,当按下
submit
时,它会转到checkForm
;如果checkForm
仅返回true
,那么它将进入CreateCustomerServlet
。为了达到这个目标,我必须改变什么? 最佳答案
尝试
onsubmit="return checkForm();"