簡體   English   中英

jsp頁面中的javascript函數

[英]javascript function in jsp page

我有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時, submit其轉到checkForm ,如果checkForm僅返回true則它將轉到CreateCustomerServlet 為了達到這個目標,我必須改變什么?

嘗試

onsubmit="return checkForm();"

你應該更換

onsubmit="checkForm"

通過

onsubmit="return checkForm();"

你應該用

onsubmit="return checkForm();"

因為只有從onSubmit返回false時,它才會停止,否則它將繼續提交表單。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM