onSubmit 返回 false 不起作用

编程入门 行业动态 更新时间:2024-10-15 00:22:46
本文介绍了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 不起作用

本文发布于:2023-11-24 01:13:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1623426.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不起作用   onSubmit   false

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!