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
javascript function in jsp page
提问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 submit
button I see that it ignore checkForm
and don't enter him , and directly go to CreateCustomerServlet
.
当我在服务器上运行此页面并按下submit
按钮时,我看到它忽略checkForm
并且不输入他,直接转到CreateCustomerServlet
.
My goals is that when press on submit
it go to checkForm
and if checkForm
returns true
only 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 false
is returned from onSubmit
will it be stopped , or else it will continue submitting the form.
因为只有false
从返回时onSubmit
才会停止,否则会继续提交表单。