我有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();"

09-28 00:21