问题描述
通常我们要做的是,我们在onsubmit事件上调用一个方法,比如< form action =onsubmit =myfunction()>
今天我看到< form action =onsubmit =return false>
。怎么运行的?我无法理解 onsubmit =return false
是什么意思。
PS:我学习Ajax。这是一篇介绍如何在不刷新页面的情况下向数据库提交数据的教程。 基本上完成了手动处理表单提交。
例如 - I know that the onsubmit event occurs when a form is submitted. Generally what we do is, we are calling a method on onsubmit event like Today I saw this, PS : I found this when I learning Ajax. It was a tutorial which explains how to submit data to database without refresh the page. For example - for validation purposeSee below code and see how it can be beneficial: 这篇关于onsubmit =“return false”的含义是什么? (JavaScript,jQuery)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
$ b $ < SCRIPT LANGUAGE =JavaScript> $ gt;
请参阅下面的代码, ;
myFunctionName(){
if(document.myForm.myText.value =='')
return false;
//当它返回false时 - 表单不会提交,也不会重定向
else
return true;
//当它返回true时,您的表单将提交并将重定向
//(实际上它是提交的一部分)您在操作中提到的id
}
< / SCRIPT>
< FORM NAME =myFormonSubmit =return myFunctionName()>
< INPUT TYPE =TEXTNAME =myText>
< INPUT TYPE =SUBMITVALUE =点击我>
< / FORM>
<form action="" onsubmit="myfunction()">
"<form action="" onsubmit="return false">"
. How it works? I could not understand what is the meaning of onsubmit="return false"
.<SCRIPT LANGUAGE="JavaScript">
myFunctionName() {
if (document.myForm.myText.value == '')
return false;
//when it return false - your form will not submit and will not redirect too
else
return true;
//when it return true- your form will submit and will redirect
// (actually its a part of submit) id you have mentioned in action
}
</SCRIPT>
<FORM NAME="myForm" onSubmit="return myFunctionName()">
<INPUT TYPE="TEXT" NAME="myText">
<INPUT TYPE="SUBMIT" VALUE="Click Me">
</FORM>