onSubmit 返回 false 不起作用 [英] onSubmit returning false is not working

查看:70
本文介绍了onSubmit 返回 false 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我完全糊涂了......我发誓这昨天有效......我今天早上醒来,我的所有表格都停止在我的项目中工作.

I'm completely confused ... I'd swear this was working yesterday ... I woke up this morning and all my forms stopped to work in my project.

所有表单都有一个onsubmit"到一个返回 false 的函数,因为它是一个 ajax 调用,所以表单永远不会被发送.

All the forms have a "onsubmit" to a function that returns false since it's an ajax call, so the form is never sent.

经过大量测试,我将问题简化为这段代码:

After a lot of tests, I simplified the question to this piece of code:

<html>
<head>
<script type="text/javascript">
 function sub()
 {
  alert ("MIC!");
  return false;
 }
</script> 
</head>
<body>

<form method = "post" id = "form1" onsubmit = "return sub()">
 input: <input type="text" name="input1" >
    <a href="#" onClick="document.getElementById('form1').submit();">button</a> 
</form>

</body>
</html>

我发誓这很完美,但今天也不行:D

I would swear that this works perfectly, but today is nor working :D

为什么我按下按钮会发送表单?

Why if I press the button the form is sent ?

我知道这是一个新手问题,但我被卡住了

I know it's a total newbie question, but I'm stuck

谢谢!

推荐答案

如果您以编程方式调用 submit(),浏览器不调用表单上的 onSubmit 事件.

Browsers do not call the onSubmit event on the form if you call submit() programmatically.

这篇关于onSubmit 返回 false 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆