Onsubmit 在 Chrome 中不起作用
我有两个表格和一个按钮。在 Firefox 中一切正常。我得到一个新窗口,其中包含 Paypal 付款,在发生所有事情的窗口中,我收到提交的 send_mail 表单,该表单将向用户发送电子邮件。我怎样才能在 Chrome 中实现这个功能?为什么它不起作用?我已经尝试过任何事情(或者我认为是这样)!
所以:
<form name="registerForm" id="registerForm" target="_blank" action="paypal_url" method="post" onsubmit="$('#send_mail').submit();">
...
</form>
<form name="send_mail" id="send_mail" action="" method="post">
...
</form>
<a onclick="$('#registerForm').submit()">Go to paypal and send confirmation mail</a>
I have two forms and a button. Everything works fine in Firefox. I get a new window, with a Paypal payment, and in the window where everything happened i get the send_mail form submitted that will send an e-mail to the user. How can I make this work in Chrome? Why it's not working? I've tried anything (or so I think)!
So:
<form name="registerForm" id="registerForm" target="_blank" action="paypal_url" method="post" onsubmit="$('#send_mail').submit();">
...
</form>
<form name="send_mail" id="send_mail" action="" method="post">
...
</form>
<a onclick="$('#registerForm').submit()">Go to paypal and send confirmation mail</a>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
除非您有充分的理由使用仅 javascript 提交,否则为什么要在出现 javascript 错误时将表单设置为不可用?
使用提交类型的标准表单输入,给它一个 id,根据需要通过 javascript 更改提交的外观或文本,并创建 onclick 和 onclick 。 onsubmit 事件作为该功能之上的一层,并让它们返回 false。更好的后备方案。
我不确定您为什么要尝试一次提交两个表单,但是这个替代方案怎么样(请注意,我尚未测试此代码,但它应该传达这个想法):
Unless you have a really good reason to use a javascript-only submit, why set up the form to be unusable if there is a javascript error?
Use a standard form input of type submit, give it an id, alter the look or text of the submit via javascript as necessary, and create onclick & onsubmit events as a layer on top of that functionality and have them return false. Better fallbacks.
I'm not sure why you're trying to submit two forms at once, but how about this alternative (note that I haven't tested this code, but it should convey the idea):
为什么不将两个提交都绑定到你的 a 上呢?
如果您希望在第一个表单之后提交另一个表单:
假设您在这里使用 jquery
why not just bind both submits to your a?
if you want the other form to submit AFTER the first one:
assuming you're using jquery here
据我了解,您想使用链接提交表单吗?
那为什么不使用“纯”javascript呢?没有 jQuery:
document.getElementById(....).submit()
或者以正常的 jQuery 方式将提交事件链接到链接:
<代码>
您也可以使用提交按钮;)
As far as i understand, you want to submit the form using a link?
Why not use "plain" javascript then? Without jQuery:
document.getElementById(....).submit()
Or link the submit event to the link in a normal jQuery way:
And you also could use the submit button ;)