javascript jsp页面中的javascript函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11792682/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 14:21:45  来源:igfitidea点击:

javascript function in jsp page

javascriptjspservletsformsonsubmit

提问by URL87

I have 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>

When I run on server this page and press on the submitbutton I see that it ignore checkFormand don't enter him , and directly go to CreateCustomerServlet.

当我在服务器上运行此页面并按下submit按钮时,我看到它忽略checkForm并且不输入他,直接转到CreateCustomerServlet.

My goals is that when press on submitit go to checkFormand if checkFormreturns trueonly then it will go to CreateCustomerServlet. what I have to change in order to get this goal ?

我的目标是,当按下submit它时,它会转到checkForm,如果仅checkForm返回,true它就会转到CreateCustomerServlet. 为了达到这个目标,我必须改变什么?

回答by Sudip Pal

Try

尝试

onsubmit="return checkForm();"

回答by M. Abbas

You should replace

你应该更换

onsubmit="checkForm"

By

经过

onsubmit="return checkForm();"

回答by Gautam

You should use

你应该使用

onsubmit="return checkForm();"

because only when falseis returned from onSubmitwill it be stopped , or else it will continue submitting the form.

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