我有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
并且不输入他,直接转到 创建CustomerServlet
.
我的目标是,当按下 submit
时,它会转到 checkForm
并且如果 checkForm
返回 true
只有这样它将转到 CreateCustomerServlet
。为了实现这个目标我必须改变什么?
最佳答案
尝试
onsubmit="return checkForm();"
关于jsp页面中的javascript函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11792682/