【问题标题】:javascript function in jsp pagejsp页面中的javascript函数
【发布时间】:2012-08-01 07:44:46
【问题描述】:

我有 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。为了实现这个目标,我必须做出哪些改变?

【问题讨论】:

  • 我想知道..我在jsp中写过同样的代码,但是在welcome.jsp中...但是它在那里不起作用,你能告诉我为什么吗?

标签: javascript jsp servlets forms onsubmit


【解决方案1】:

你应该使用

onsubmit="return checkForm();"

因为只有当falseonSubmit返回时才会停止,否则会继续提交表单。

【讨论】:

    【解决方案2】:

    你应该替换

    onsubmit="checkForm"
    

    onsubmit="return checkForm();"
    

    【讨论】:

      【解决方案3】:

      试试

      onsubmit="return checkForm();"
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-01-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-07-16
        • 1970-01-01
        相关资源
        最近更新 更多